How to Use ES6 in node and ES6 in node
ES6 + is great, but many advanced functions node is not supported, you need to use babel to convert to ES5,
1. Install babel Dependencies
Npm install babel-core -- save-dev
2. Install babel-register
Npm install babel-register -- save-dev
3. babel conversion configuration. Add the. babelrc file to the project root directory.
{"Presets": ['es2015 ']}
At this time, we need to install the es6 conversion module. Note that babel does not help us directly convert the code. It requires a conversion module.
Npm install babel-preset-es2015 -- save-dev
4. Add the entry file index. js to the project root directory
Require ('babel-register '); require ('./app. js ')
Now all ES6 syntaxes can be used.
Test it below
App. js
Import express from 'express '; class Person {say () {console. log ('hello') ;}} let app = express (); app. get ('/', (res, req) =>{}) app. listen (3000, (res) => {new Person (). say ();});
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.