简体   繁体   中英

Npm CLI global variable

I am developing a CLI and it is all based on a uid that i have to store somehow. What is the most viable solution. I have tried with using fs but the file created was placed in the path in which the command is ran.

#!/usr/bin/env node
const program = require("commander");
const { saveUid } = require("./commands");
program
    .command('setuid <uid>')
    .alias('b')
    .description('Set the uid of the album.')
    .action(uid => {
        saveUid(uid);
    })
program.parse(process.argv);

So, any idea to for the saveUid function?

const saveUid = (uid) => {

}
module.exports = {
    saveUid
}

You can use the mkdirp module on NPM to make a folder in any directory. Once you open the directory you can use fs to make a file in it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM