mjs

What is the difference between .js and .mjs files?

隐身守侯 提交于 2020-01-23 08:01:52
问题 I have started working on an existing project based on nodejs. I was just trying to understand the flow of execution, where I encountered with some .mjs files. I have searched the web where I found that these are module based JS files. I want to know how is it different from .js files (how does it benefit) ? 回答1: Node.js's native module system is CommonJs. It has experimental support for the standard ES6 module system and using a .mjs file extension is part of one way to trigger that support.

Fail to create variable using eval in Node.js ES6

时光总嘲笑我的痴心妄想 提交于 2019-12-23 04:39:11
问题 It seems not possible to create a variable using eval in Node.js ES6 but I can't understand why. This happens to me on CentOS 7, but I don't believe OS is the problem here. Regular Node.js file (test.js): eval("var a=1"); console.log(a); Make the same file with .mjs extension to run with Node.js ES6 (test.mjs): eval("var a=1"); console.log(a); After that, run the 2 files with Node.js, and Node.js ES6: $ node test.js 1 $ node --experimental-modules test.mjs (node:9966) ExperimentalWarning: The