Getting below error when i try to use async/await with NodeJs 4.x. Any issue with the below sample code or should i use alternate ?
async function main ()
Node 4.x Does not support async await out of the box. In your cade I believe that the easiest way to add support to it will be though babel-node.
Run npm install babel-cli --save-dev
and add this to your package.json
"scripts": {
"start": "babel-node --presets env src/index.js"
},
you may need to change src/index.js by your entry point file.
then install the presets
npm install babel-preset-env --save-dev
then start your project using
npm start
this shall do the trick.
The advantage of this over installing asyncawait is that you don't need to change anything in your code, as asyncawait gives you functions that have a similar behavior to async and await operator but does not really transpile your code.
PS: you can specify you presets in a .babelrc file too, feel free to read more about it here https://babeljs.io/docs/en/config-files#file-relative-configuration