本篇内容主要讲解“node.js 8.5新特性有哪些”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“node.js 8.5新特性有哪些”吧!Node.js 8.5
本篇内容主要讲解“node.js 8.5新特性有哪些”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“node.js 8.5新特性有哪些”吧!
Node.js 8.5 新特性
最近 Node.js 发布了8.5版本,在这个版本里,Node 添加了3个激动人心的新特性。
支持 ES Module
此次版本迭代中,Node 终于支持了开发者呼声***的 ES 模块提案。这意味着,你可以直接使用import关键字引入需要的模块。 Node 8.5 可以运行如下代码:
`import fs from 'fs'`
使用es模块,你需要注意,引入文件的扩展名应为 mjs,同时使用 --experimental-modules标识。
在 Node.js 中使用 ES 模块的限制:
import(), V8引擎将在下一版本支持,
import.meta, V8引擎暂不支持,
不支持 require('./foo.mjs')
性能监控
在 Node.js 8.5 中,可以调用 mark() 和 measure() API,监控 Node.js 事件执行时间。
在 Node.js 8.5 中,你可以这样使用:
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)
官方文档:https://nodejs.org/api/perf_hooks.html
fs 模块添加文件复制功能
Node.js 8.5 推出了更高级的文件系统,在这个版本你可以直接通过 fs 模块复制某个文件的代码:
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') })
到此,相信大家对“Node.js 8.5新特性有哪些”有了更深的了解,不妨来实际操作一番吧!这里是编程网网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
--结束END--
本文标题: Node.js 8.5新特性有哪些
本文链接: https://www.lsjlt.com/news/85974.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0