Configure ES Modules and npm Scripts
We will use ES Modules throughout the tutorial.
Open package.json and configure the module system and scripts.
The type module property allows us to use import and export syntax.
The development script uses Node.js watch mode to restart the server when files change.
package.json
{
"name": "nodejs-rest-api",
"version": "1.0.0",
"private": true,
"type": "module",
"scripts": {
"start": "node src/server.js",
"dev": "node --watch src/server.js",
"test": "node --test"
}
}Configures the project to use ES Modules and defines application execution scripts.
Key Takeaways
ES Modules use import and export.
The type module setting enables ES Module interpretation.
npm scripts simplify application execution.