What's new in Node.js 8.5? | @RisingStack
source link: https://blog.risingstack.com/whats-new-in-node-js-8-5/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Co-Founder of RisingStack, EM at Uber
With the recent release of Node.js 8.5, three very exciting new features landed in the Node.js core. In the short blogpost, you are going to learn about them!
ECMAScript Modules in Node.js!
One of the most requested features of Node.js was to provide support for ESM. What it means is that you can now use the import
keyword, without transpiling your code. So from now on, you can run snippets like these:
import fs from 'fs'
The only two things you have to pay attention to is to name your file with the mjs
extension and to run Node.js with the --experimental-modules
flag.
For now, using ESM has some limitation in Node.js:
import()
, pending newer V8 release used in Node.js,import.meta
, waiting for V8 to implement it,require('./foo.mjs')
, not supported.
You can check the corresponding pull request here: https://github.com/nodejs/node/pull/14369/files. Thanks for the amazing work Bradley Farias, Guy Bedford and Jan Krems!
Performance Hooks
An initial implementation of the Performance Timing API is also shipped with Node.js 8.5.
The User Timing mark()
and measure()
APIs are implemented, as is a Node.js specific flavour of the Frame Timing for measuring event loop duration.
You can start using it with Node.js 8.5 this way:
const { performance } = require('perf_hooks')
performance.mark('A')
setTimeout(() => {
performance.mark('B')
performance.measure('A to B', 'A', 'B')
const entry = performance.getEntriesByName('A to B', 'measure')
console.log(entry.duration)
}, 10000)
To learn more, check out the official documentation here: https://nodejs.org/api/perf_hooks.html.
You can check the corresponding pull request here: https://github.com/nodejs/node/pull/14680/files. Thanks for the amazing work James M Snell!
File copy with the core fs
module
With Node.js 8.5, a new File System feature is shipped as well - now you can copy files using the core fs
module!
const fs = require('fs')
fs.copyFile('source.txt', 'destination.txt', (err) => {
if (err) {
// handle error properly, not just console.log
return console.error(err)
}
console.log('source.txt was copied to destination.txt')
})
You can check the corresponding pull request here: https://github.com/nodejs/node/pull/15034/files. Thanks for the amazing work Colin Ihrig!
We hope with these amazing new feature additions you can do even more great libraries and applications using Node.js! Do you already have a library which depends on these features? Let us know in the comments!
You can check out all the fixes and features what Node.js 8.5 brought here: https://nodejs.org/en/blog/release/v8.5.0/.
Recommend
-
105
Please wait... We are checking your browser... blog.cloudflare.com What can I do to prevent this i...
-
87
A CEO's Guide to Emacs Josh Stella | November 11, 2015 ...
-
80
When I first started to learn about accessibility I wanted to write automated tests to ensure that assistive technology devices, like screen readers, were interpreting my pages correctly. Because I'm not a daily screen reader user, I figured it...
-
51
Invite Event on iOS Starts Soon. Sign-Up Monday.
-
41
This post highlights some git features that might be less used/known, but can end up saving you when things go south in the codebase.
-
44
前几天 Google IO 上 V8 团队为我们分享了《What's New in JavaScript》主题,分享的语速很慢推荐大家可以都去听听就当锻炼下听力了。看完之后我整理了一个文字版帮助大家快速了解分享内容,嘉宾主要是分享了以下几点: JS 解析快了
-
2
Business Thinking Goodhart's Law Isn't as Useful as You Might Think By
-
4
First Impressions of Bluesky's Brand New iOS App 3/3/2023 Created when Jack Dorsey was CEO of Twitter, Bluesky is a kind of social network reimagined as an ope...
-
3
VR Gaming Asgard's Wrath 2: Meta's AAA Bet On Quest 2 Promises '60 Hours Of Exploration' In 2023 ...
-
5
Quest 3 Controllers Approved By FCC Ahead Of Launch Skip to content...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK