Categories
JavaScript Answers

How to get the hostname of current request in Node.js Express?

Spread the love

Sometimes, we want to get the hostname of current request in Node.js Express.

In this article, we’ll look at how to get the hostname of current request in Node.js Express.

How to get the hostname of current request in Node.js Express?

To get the hostname of current request in Node.js Express, we can use the os.hostname method.

For instance, we write

const os = require("os");
os.hostname();

to call os.hostname to return the hostname of the current request.

Conclusion

To get the hostname of current request in Node.js Express, we can use the os.hostname 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 *