Nodemon for development

Keep the server running,

npm start

Change the Hello World! text to Hello World from JS Mates!.

The server won't refresh the values. It will still show the previous text. You need to stop the server and restart again. It is OK to do for a couple of times. But in real development, it will be very annoying and not productive to restart for every change.

There is a package called nodemon to solve this issue during development,

Let's install nodemon as dev dependencies.

npm install --save-dev nodemon

or the shortcut version,

npm i -D nodemon

Change the start script to use nodemon,

"scripts": {
    "start": "nodemon server.js",
    ...
}

Stop the server if already running, then start again using npm start. By default nodemon listens for js, mjs, and json file changes. It listens to all the folders for those files inside the root folder.

Go and change the text back to Nodemon says Hello World!. You will see the server restarting on every file changes.

Is it ok to use nodemon for production?

Node script is better suited for production. Node caches the server files in memory to provide stability. Your server will continue to run with the previous state from the memory unless you restart it. This will help to provide good server uptime in production apps.