Node.js 在进程结束时执行函数

Node.js 在进程结束时执行函数,node.js,inquirer,Node.js,Inquirer,函数initNpm(){ //服务() const spawn_option={cwd:'./'+projet,detached:true} var child=exec('npm init',spawn_选项,函数(err,stdout,stderr){ if(err){console.log(err)} //console.log('over'); }); child.stdout.on('data',函数(data){ 进程.标准输出.写入(数据); process.stdin.resum

函数initNpm(){
//服务()
const spawn_option={cwd:'./'+projet,detached:true}
var child=exec('npm init',spawn_选项,函数(err,stdout,stderr){
if(err){console.log(err)}
//console.log('over');
});
child.stdout.on('data',函数(data){
进程.标准输出.写入(数据);
process.stdin.resume();
});
process.stdin.on('readable',function(){
var chunk=process.stdin.read();
if(块!==null){
child.stdin.write(块);
}
});
exec('npm install express mongoose nodemon',spawn_选项,函数(err,stdout,stderr){
if(err){console.log(err)}
});
}
函数服务(回调){
for(设i=0;i{
const auth=wait inquirer.authentication();
console.log(auth)
//const auth=auth.answers;
//const auth=wait auth.authentication();
//console.log(身份验证提示)
//让parser=JSON.stringify(auth);
让donnees=auth.name+“:{+'\n”+
类型:“+auth.type+”,“+”\n+
必需:“+auth.required+”,“+”\n+
“唯一:“+auth.unique+”\n”+
"}"     
authDatabase=“DATABASE\u URLAUTH=mongodb://localhost/users";   
fs.writeFile('./'+projet+'/models/authentication.js',donnees,函数(err){
if(err)返回控制台。error(err);
});
fs.appendFile('./'+projet+'/.env',authDatabase,function(err){
如果(错误)抛出错误;
});
/*做
{
const securityRepeated=async()=>{
const authreated=wait inquirer.authentication();
console.log(auth);
让donneesRepeated=“,”+
authRepeated.name+“:{+'\n”+
类型:“+authRepeated.type+”,“+”\n+
必需:“+authRepeated.required+”,“+'\n”+
“唯一:”+authRepeated.unique+“\n”+
"}"
fs.appendFile('./'+projet+'/models/authentication.js',donneesRepeated,函数(err){
如果(错误)抛出错误;
});
}
securityRepeated()
}
while(auth.addAttribute==true)*/
/*exec('svn checkouthttps://github.com/morseck00/PROTO_BOX/trunk/AuthentificationJWT“,{cwd:'./'+projet+'/routes'},函数(err、stdout、stderr){
如果(错误){
log(`error:${err.message}`);
返回;
}
如果(标准){
log(`stderr:${stderr}`);
返回;
}
log(`stdout:${stdout}`);
});*/
}
保安()
}
回调();

}
我想我已经解决了!我将initNpm函数作为回调放在服务函数中,并在“npm init”命令中添加“-y”,这样它就不会出现在控制台中了!
tks

您好-欢迎来到StackOverflow!除非您发布您当前正在使用的代码,否则我们将无法帮助您。如果您可以将此添加到您的问题中,那么希望有人能够为您指出正确的方向。是的,您是对的!我添加了代码!