Best way to persist user preferences with npm/nodejs command line utility

Looking at the questions and comments i think there are two problems to solve:

  1. Where to save it: If there are user specific settings, then by common pattern in Linux its best saved in the hidden directory in user's home directory. Hence you can best keep it in directory $HOME/.{yourAppName}/someFile

    E.x: Pidgin saves it in: /home/kushal/.purple/...
    ("." prefix to folder name makes it hidden)
       
    You can save it in: /home/$HOME/.myawesomeNPMModule/...

    NOTE: If you are also targeting the windows platform, then you need a platform check and decide which path to use.

    In windows Vista and above it goes in
    $WIN_INSTALLATION_DRIVE\Users\$USER_NAME\AppData\Local\YourAppName...

    In windows XP it goes in 
    $WIN_INSTALLATION_DRIVE\Documents and Settings\$USER_NAME\Local Settings\Application Data\Local\YourAppName\...

    Yes cross platform makes life difficult, or atleast adds few IF statements. ;)

  2. How to save it: You can save the credentials in JSON file easily. Now as you need the data to be secured and also not read by illegal access, the best way is to encrypt it. NodeJs Crypto module is very easy to use and you can use it in few lines to encry/decrypt your settings file. Your application will only be aware of encryption passwords and hence your application will only be able to decrypt it.

    I would recommend AES-192 for encrypting the files.

Hope it helps!!