[英]Npm CLI global variable
I am developing a CLI and it is all based on a uid that i have to store somehow. 我正在开发一个CLI,它全部基于我必须以某种方式存储的uid。 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.
我尝试使用fs,但是创建的文件被放置在运行命令的路径中。
#!/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? 那么,对于saveUid函数有什么想法吗?
const saveUid = (uid) => {
}
module.exports = {
saveUid
}
You can use the mkdirp
module on NPM to make a folder in any directory. 您可以使用NPM上的
mkdirp
模块在任何目录中创建一个文件夹。 Once you open the directory you can use fs to make a file in it. 打开目录后,您可以使用fs在其中创建文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.