TLDR

node_js_nvm_linux

What is Nodemon?

Nodemon is a useful tool that automatically restarts your Node.js application when it detects changes in your source code. This can save you time and hassle when working on an Express.js app, as you don’t have to manually stop and start your server every time you make a change. In this post, we’ll go over how to install and use Nodemon on an Express.js app.

Installing Node.js and npm

First, make sure you have Node.js and npm (Node Package Manager) installed on your computer. You can check this by running the following commands in your terminal:

node -v
npm -v

If these commands return version numbers, you have Node and npm installed. If not, you can download and install them from the official Node.js website.

Installing Nodemon

Next, we’ll install Nodemon by running the following command:

npm install -g nodemon

The -g flag installs Nodemon globally, so you can use it on any project on your computer.

Using Nodemon on an Express.js App

Once Nodemon is installed, you can use it to start your Express.js app by running the following command from the root directory of your project:

nodemon app.js

Make sure to replace app.js with the name of your main Express file.

Using Nodemon with npm Scripts

You can also use nodemon with npm script.

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

And then you can run your express app with

npm start

Conclusion

In conclusion, Nodemon is a great tool for Express.js developers that can save a lot of time and hassle when working on a project. By automatically restarting the server when changes are made, it eliminates the need to manually stop and start the server every time you make a change. With Nodemon, you can focus on coding and let the tool handle the rest.

Happy learning/coding 😎