Tips: Restarting a Node process without file changes

Join the AI Workshop to learn more about AI and how it can be applied to web development. Next cohort February 1st, 2026

The AI-first Web Development BOOTCAMP cohort starts February 24th, 2026. 10 weeks of intensive training and hands-on projects.


I had the need to run a Node project and if that failed for some reason, run it again.

I had the idea of using nodemon, which is the way to restart a node process when a file changes.

I was thinking it did the same if the process crashed but it’s not how it works.

So I found this solution.

If the process crashes, I use the command line to run the touch command on the main app file, so nodemon detects a change in the file and restarts the process:

nodemon -x 'node app.js || touch app.js'

Simple, works.

Of course in a real environment you’d use a robust solution like pm2 (see my tutorial how to use pm2 to serve a Node.js app) but this is something I need to run for a couple hours on my local machine and it works.

Update: an alternative is using Forever https://www.npmjs.com/package/forever

Lessons in this unit:

0: Introduction
1: Axios crashes the Node.js process when the request fails
2: How to set up a cron job that runs a Node.js app
3: How to get both parsed body and raw body in Express
4: Interact with the Google Analytics API using Node.js
5: How to bulk convert file names using Node.js
6: How to deep copy JavaScript objects using structuredClone
7: How to handle file uploads in Node.js
8: How to send an email using nodemailer
9: Logging all the requests coming through an Express app
10: How to upload an image to S3 using Node.js
11: How to read a CSV file with Node.js
12: How to set the current working directory of a Node.js program
13: How to upload files to S3 from Node.js
14: How to write a CSV file with Node.js
15: Where to host a Node.js app
16: Parsing JSON with Node.js
17: nodemailer, how to embed an image into an email
18: The Pug Guide
19: ▶︎ Restarting a Node process without file changes
20: How to use Sequelize to interact with PostgreSQL