我正在尝试使用Node版本6.2.1和我的一些代码.计划将大多数面向超回调的代码迁移到看起来更干净且可能表现更好的代码.
我不知道为什么,当我尝试执行节点代码时终端抛出错误.
helloz.js
(async function testingAsyncAwait() {
await console.log("Print me!");
})();
Run Code Online (Sandbox Code Playgroud)
日志 -
BOZZMOB-M-T0HZ:rest bozzmob$ node helloz.js
/Users/bozzmob/Documents/work/nextgennms/rest/helloz.js:1
(function (exports, require, module, __filename, __dirname) { (async function testingAsyncAwait() {
^^^^^^^^
SyntaxError: Unexpected token function
at Object.exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:513:28)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Function.Module.runMain (module.js:575:10)
at startup (node.js:160:18)
at node.js:456:3
BOZZMOB-M-T0HZ:rest bozzmob$ node -v
v6.2.1
Run Code Online (Sandbox Code Playgroud)
我错过了什么?请给我一些启示.
更新1:
我尝试使用Babel作为Quentin建议,但是,我仍然收到以下错误.
更新的代码 -
require("babel-core/register");
require("babel-polyfill");
(async function testingAsyncAwait() {
await console.log("Print …Run Code Online (Sandbox Code Playgroud)