How to find home directory in platform agnostic way with Node.js?

Sometimes, we want to find home directory in platform agnostic way with Node.js.

In this article, we’ll look at how to find home directory in platform agnostic way with Node.js.

How to find home directory in platform agnostic way with Node.js?

To find home directory in platform agnostic way with Node.js, we can use the os.homedir method.

For instance, we write

const os = require('os');

console.log(os.homedir());

to call os.homedir to return the home directory path as a string.

Conclusion

To find home directory in platform agnostic way with Node.js, we can use the os.homedir method.