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 repl.it.
Top comments (3)
You can also use the method directly with esm:
Thanks for sharing it, Andrew.
It really helped me. Thanks man