Node.js 10 is releaed and will become the long term support version (replacing Node 8) in october 2018.
Highlights:
- ES6 module support:
- given the ubiquity of node.js native modules (CommonJS) this was a hard nut to crack
- Both systems provide and use module elements differently
- Node.js modules work with module.exports and require
- EJS modules work with export and import
- a difference between both module systems is that node modules load synchronously and ES6 modules load asynchronously. Tools bridging both worlds like webpack load ES6 modules syncronously into Node.js. These tools have allowed isomorphic javascript, running both in the browser and in Node. The node team has not gone this way and stuck to the standard: they load ES6 modules synchronously.
- Node 10 allows usage of ES6 modules only in files with the new .mjs extension (module javascript). So .js files keep on using module.exports and require.
- How do you access a module from the other module universe?
- You can import from a Node .js file into a ES6 .mjs file, but you can only use a default import. That is logical, as Node's module.exports only exports one thing. This one thing can be an object or a function, that can encapsulate more stuff.
- You can import from a .mjs file into a Node .js file, but only by explicitly making the import asynchronous using await import(). Again this seems a logical choice.
- This image from a Medium article sums it up nicely
- If you import a file without an extension Node will first look for a .mjs file. If it does not find it, it will look for a .js file. This leaves the door open to using your ES6 .js files, without renaming them.
- This seems to be a workable system, but I'm not sure I like the degradation of ES6 modules to second class .mjs citizens. Well, this is a work in progress, and I think for now the Node team is awating the reaction from the developer community
- API changes
- fs.promises: fs functions returning promises without having to use util.promisify()!
- standard numeric codes for error messages
- console.table
- npm 6
- better security and new npm audit command to check a package for vulnerabilities
- warnings if you download a package with security issues
- speed bump
No comments:
Post a Comment