Categories
JavaScript Answers

How to programmatically shut down an instance of Express.js?

Spread the love

Sometimes, we want to programmatically shut down an instance of Express.js.

In this article, we’ll look at how to programmatically shut down an instance of Express.js.

How to programmatically shut down an instance of Express.js?

To programmatically shut down an instance of Express.js, we can call the close method.

For instance, we write

const server = app.listen(3000);

const handler = () => {
  server.close();
};

to call the app.listen with the port number to return an Express server object.

Then we call server.close to shut down the Express instance in the handler function.

Conclusion

To programmatically shut down an instance of Express.js, we can call the close method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *