ThomasReggi
ThomasReggi

Reputation: 59475

What is the simplest amount of code that would prevent a node process from exiting?

I'm looking for a way to log text in a javascript node.js file in the terminal and not have that process exit.

console.log('hello-world')
process.doNotExit()

There are many different things I've done in the past like connect to a database that prevent the process from exiting.

I'm looking for something different from the forever module.

Upvotes: 1

Views: 27

Answers (1)

skypjack
skypjack

Reputation: 50550

You can use setInterval and do nothing:

var i= setInterval(function(){}, 2147483647);

The value comes from here, it's approximately 25 days.
Use clearInterval or unref when you are ready to exit (see here for further details).

Naïve, but pretty easy. Isn't it?

Upvotes: 1

Related Questions