| Level Navigation: 1 | 2 | 3 | (4ℹ️) | (5ℹ️) | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14⚡ | 15⚡ | (16ℹ️) | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26⚡ | 27⚡ | 28⚡ | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39⚡ | 40⚡ |
Add a dev script to package.json:
Show Me: npm scripts with nodemon and node
{
"type": "module",
"scripts": {
"start": "node src/index.js",
"dev": "nodemon src/index.js"
}
}
Understanding the scripts:
npm start: Runs your server with Node.js. Use this for production or when you want to run the server once.npm run dev: Runs your server with nodemon, which automatically restarts the server whenever you save changes to your files. This speeds up your development workflow—no need to manually stop and restart the server after each code change.ES6 Modules ("type": "module"):
"type": "module" in package.json enables ES6 module syntax throughout your project.import and export instead of CommonJS require() and module.exports:
// ES6 Modules (with "type": "module")
import express from 'express';
export default app;
// CommonJS (without "type": "module")
const express = require('express');
module.exports = app;