Home > Article > Web Front-end > Introduction to the method of using es6 in express (detailed)
The content of this article is an introduction to the method of using es6 in express (detailed). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
The JavaScript standard provided on the express official website is es5, which cannot directly run es6. If you want to use es6 writing in express, you can use the transcoder Babel to transcode.
In development environment
1. Install babel-cli in express project
$ npm install --save-dev babel-cli
2. Install presets
npm install --save-dev babel-preset-es2015 babel-preset-stage-2
3. Add the running script in package.json
{ ... "scripts": { "start": "babel-node index.js --presets es2015,stage-2" } ... }
4. Now you can use the es6 writing method. Write a paragraph of es6
5. Run
npm start
Just started learning When using express, you will encounter a problem: every time you change a little bit of code, you need to restart the service. We hope to achieve the "hot update" effect. Next, we can use nodemon to monitor file modifications to achieve the hot update effect instead of restarting the service every time.
1. Install nodemon
npm install --save-dev nodemon
2. Modify the script
{ ... "scripts": { "start": "nodemon index.js --exec babel-node --presets es2015,stage-2" } ... }
3. Run
npm start
Now change the js code without restarting the service to achieve the effect
The above is the detailed content of Introduction to the method of using es6 in express (detailed). For more information, please follow other related articles on the PHP Chinese website!