kabal kabal - 1 year ago 103
Node.js Question

node.js - how to get the OS platforms user data folder

I am a complete novice at Node.js

I am looking for a way to get the userdata folder using node.js, that will work on both windows, and macOS

the node.js instance would be running on the user's machine

this would return the following:

C:\Documents and Settings\JohnD\Application Data - Windows XP

C:\Users\JohnD\AppData\Roaming - Windows Vista and Up

/Users/JohnD/Library/Preferences - MacOS

is this possible?


Answer Source

You can check user environment which is stored in process.env

Also, take a look at process.platform

To be specific:

% node                                                                                                                                 
> console.log(process.env.HOME)
> console.log(process.platform)

Having this information, you will be able to achieve what you need.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download