How to get the current home directory of the user in Node.js?

Published March 20, 2021

To get the current user home directory, you can use the homedir() method from the os module in Node.js.

/* Get home directory of the user in Node.js */

// import os module
const os = require("os");

// check the available memory
const userHomeDir = os.homedir();
  • The method returns the path to the directory as a string.

See the above code live in

Feel free to share if you found this useful 😃.

Share on: Facebook Twitter