Create project and install dependencies
mkidr my-app && cd my-app
npm init -y
npm i -D @babel/cli @babel/core @babel/node @babel/preset-env
npm i expresss
Create .babelrc
{
"presets": ["@babel/preset-env"]
}
Write a web service
mkdir src/ && touch src/app.js
In app.js
import express from 'express';
const app = express()
const port = 9098
app.get('/', (req, res) => {
res.send('ok')
})
app.listen(port, () => {
console.log(`app listen on port ${port}`)
})
package.json
Include "type": "module"
at the root level and add the start script "start": "npx nodemon --exec babel-node src/app.js"
inside the scripts
section.
Start the project
npm start