Skip to Content
Learning JavaScript Data Structures and Algorithms - Third Edition
book

Learning JavaScript Data Structures and Algorithms - Third Edition

by Loiane Avancini
April 2018
Beginner to intermediate content levelBeginner to intermediate
426 pages
10h 19m
English
Packt Publishing
Content preview from Learning JavaScript Data Structures and Algorithms - Third Edition

Using native ES2015 imports in Node.js

It would be nice if we could use the ES2015 imports in Node.js so that we don't need to transpile our code. Starting with Node 8.5, we can use ES2015 imports in Node.js as an experimental feature.

For this example, we will create a new folder inside chapter01 called 17-ES2015-Modules-node. We will copy the files 17-CalcArea.js, 17-Book.js, and 17-ES2015-ES6-Modules.js to this folder and we will change the extension from js to mjs (the .mjs extension is a requirement so that this can work). In the 17-ES2015-ES6-Modules.mjs file, we will update the imports, adding the .mjs extension to it as follows:

import * as area from './17-CalcArea.mjs'; 
import Book from './17-Book.mjs'; 

To execute the code, we will ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning JavaScript Data Structures and Algorithms

Learning JavaScript Data Structures and Algorithms

Loiane Avancini

Publisher Resources

ISBN: 9781788623872Supplemental Content