📝 Posted on 2021-10-29T17:06:49Z
⏳ 1 min read
How to use ES6+ features in nodejs
#javascript#webdev#node#beginners
This article is about how to use
es6+
in nodejs projectInitialising project with npm
npm init -y
Installing babel plugins for es6+ features
npm i -D @babel/cli @babel/core @babel/plugin-proposal-class-properties @babel/plugin-transform-runtime @babel/preset-env
Adding babel support for project
touch .babelrc
Paste the following content in
.babelrc
```javscript
{
"presets": ["@babel/preset-env"],
"plugins": ["@babel/plugin-proposal-class-properties", "@babel/transform-runtime"]
}bash "build": "babel src -d dist", "start": "npm run build && node dist"Babel is not a compiler or interpreter it is just a transpiler so we have to transpile `es6` to `es5` using babel then we have to execute that transpiled code. For that we can write npm script. Add the following script to `package.json`
```
Now create
src
folder and start writing es6+
code inside that folder. Run npm start
it will create dist
folder inside that folder we can find transpiled code.
Cheers!!! You can now extend your support by buying me a Coffee.
