kabal kabal - 1 month ago 5x
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?



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.