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

I am writing a nodejs cli utility (an NPM module designed to be installed globally) that should store some user-defined values. What is the best way to store these values ​​in a system?

For example, should I create my own configuration file in the say: section /etc/{my-utility-name}/conf.jsonand create this directory + file in my installscript

( https://npmjs.org/doc/misc/npm-scripts.html )

+4
source share
3 answers

Looking at questions and comments, I think there are two problems:

  • . , Linux . , $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/...

    . Windows, , .

    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\...

    , - , , IF.;)

  • . JSON. , , , , - . NodeJs Crypto , / . , , , .

    AES-192 .

, !

+1

, JSON . , , - SQLite .

, . , , , .

+1

API cli-config NodeJS, :

https://github.com/tohagan/cli-config .

1:

defaults.config, ~/.<appname>.config, , debug true. , .

var config = require('../cli-config')
             .getConfig({dirname: __dirname, override: {debug: true}});

2:

defaults.config, ./config.json, . ./config.json , defaults.config, defaults.config .

var config = require('../cli-config').getConfig({
    dirname: __dirname,          
    clone: true,                 
    configFile: './config.json', 
    merge: 'deep'                
});

3:

The command line parser returns an object that can be used to override system settings or user settings. This parser can be configured using the cli parameter . For more information on command line parsing options, see minimist .

var config = require('../cli-config').getConfig({
    dirname: __dirname,
    cli: { 
        boolean: {
            'd': 'debug',
            'v': 'verbose'
        } 
    } 
});

Sets config.debug and config.verbose to true.

$ myapp -d -v  
+1
source

All Articles