How to set up babel for express-js .
👉 How to set up babel for express-js .
Browser not understand es6 code so use babel.
1. Firstly install express
2. After install express js than
npm install -D @babel/cli @babel/core @babel/preset-env
3. Make a file with .babelrc and Paste this code.
{ "presets": ["@babel/preset-env"] }
4. Write this code in Package.json in Script
"scripts": { "start": "babel index.js -w --out-dir prd", "dev-serve": " nodemon prd/index.js" },
5. After this run in terminal
npm start //This is use for showing compiler data one by one.
6. and open a another terminal and write
npm run dev-serve
--------------------------If Not have index.js file -------------------------------------------------------- 7.
index.js code for showing data Hello word import express from 'express'; const app = express() const port = 3000 app.get('/', (req, res) => { res.send('Hello World!') }) app.listen(port, () => { console.log(`Example app listening on port ${port}`) })
Comments
Post a Comment