07-21-2023, 10:52 AM
I am experimenting with the `await` keyword in Node.js. I have this test script:
"use strict";
function x() {
return new Promise(function(resolve, reject) {
setTimeout(function() {
resolve({a:42});
},100);
});
}
await x();
But when I run it in node I get
await x();
^
SyntaxError: Unexpected identifier
whether I run it with `node` or `node --harmony-async-await` or in the Node.js 'repl' on my Mac with Node.js 7.5 or Node.js 8 (nightly build).
Oddly, the same code works in the Runkit JavaScript notebook environment:
What am I doing wrong?
"use strict";
function x() {
return new Promise(function(resolve, reject) {
setTimeout(function() {
resolve({a:42});
},100);
});
}
await x();
But when I run it in node I get
await x();
^
SyntaxError: Unexpected identifier
whether I run it with `node` or `node --harmony-async-await` or in the Node.js 'repl' on my Mac with Node.js 7.5 or Node.js 8 (nightly build).
Oddly, the same code works in the Runkit JavaScript notebook environment:
[To see links please register here]
What am I doing wrong?