Once the project dir is created and initialized, install nodemon
for development only
npm install nodemon --save-dev
Then place the nodemon in the npm start script
{
...
"main": "index.js",
"scripts": {
"start": "nodemon src/index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
...
}
Now the application will keep running once started with npm start
from the command line.
To use modern JS/ECMAScript install Babel
npm install @babel/core @babel/node --save-dev
Next, add it to the npm start script
{
...
"main": "index.js",
"scripts": {
"start": "nodemon --exec babel-node src/index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
...
}
Different JS features are activated by adding them as presets to Babel. Add the most common Babel preset
npm install @babel/preset-env --save-dev
In the project root folder create Babel config. .babelrc
is used for specific files or
parts of the project, and babel.config.js
for global settings.
touch babel.config.js
Place the following inside
module.exports = {
presets: [
'@babel/preset-env',
],
targets: {
node: 'current',
},
};
Adapted from The minimal Node.js with Babel Setup