/* Code-Comments */

Rimraf To Clean Restart A Node Server

November 20, 2019

One of the challenges of using nodemon to monitor changes to a node server and restart is if some changes get cached.

I came across rimraf in a project recently and it seems capable of handling this issue nicely.

Instead of having an npm script of

"scripts": {
  "dev": "nodemon dist/index.js",
},

The project had the following chain:

"scripts": {
  "build": "babel src —out-dir dist",
  "dev": "nodemon —exec npm run restart",
  "restart": "rimraf dist && npm run build && npm run start",
  "start": "node dist/index.js"

I thought this was clever. It’s an easy way to ensure that when you run your server, it’s a clean install of packages and you’re not looking at outdated code.


Stephen Weiss

Thanks for reading! My name's Stephen Weiss. I live in Chicago with my wife, Kate, and dog, Finn.
Click here to see the archives of my weeks in review and sign up yourself!