Sometimes, we want to run Node.js app with ES6 features enabled.
In this article, we’ll look at how to run Node.js app with ES6 features enabled.
How to run Node.js app with ES6 features enabled?
To run Node.js app with ES6 features enabled, we install a few packages.
We enable ES6 features by running
npm install --save-dev babel
npm install --save-dev babel-cli
npm install --save-dev babel-preset-es2015
npm install --save-dev babel-preset-stage-0
npm install --save-dev nodemon
to install Babel and nodemon.
Then we create a .babelrc file in the project root and add
{
"presets": ["es2015", "stage-0"]
}
to let us run our project with ES6 features.
Then in package.json, we write
{
//...
"scripts": {
"watch": "babel -w src/ -d dist/",
"build": "babel src/ -d dist/",
"serve": "babel -w src/ -d dist/ | nodemon --watch dist",
"test": "echo \"Error: no test specified\" && exit 1"
}
//...
}
to run babel
with nodemon
to let us run our Node.js app with Babel.
Conclusion
To run Node.js app with ES6 features enabled, we install a few packages.