package.json
"scripts": {
"build": "babel app.js -d dist",
"start": "npm run build && nodemon dist/app.js"
},
...
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.7.0",
"nodemon": "^1.18.9"
}
app.js
import express from 'express';
const app = express();
const port = process.env.PORT || 3000;
app.use('/', (req, res) => {
res.send('World 1');
});
app.listen(port, () => {
console.log('Example app listening on port 3000!');
});
When I run npm start
Browser output
When changes are made to the code, app restarts.
Here I made 'World 1' to 'World 2'
But when I refresh the browser it still shows World 1
If I do npm start
again and rebuild, then the browser shows 'World 2'
How do I fix this?
"start": "nodemon dist/app.js --exec babel-node --presets babel-preset-env",
For babel to work with nodemon you start script should be as above.
Please go through this.