在Sails.js应用程序中运行CLI命令
我需要在提升应用程序后立即运行PostgreSQL脚本。例如,我需要从应用程序执行以下命令:在Sails.js应用程序中运行CLI命令,sails.js,command-line-interface,Sails.js,Command Line Interface,我需要在提升应用程序后立即运行PostgreSQL脚本。例如,我需要从应用程序执行以下命令:psql-ddoghouz-a-fscript.sql。有没有办法做到这一点呢?这取决于你如何提升你的应用程序。如果您使用: node app.js 你可以加上 sails.on('lifted', function yourEventHandler () { console.log('lifted') }); 在你的app.js文件中,在line sails.lift(rc('sails')
psql-ddoghouz-a-fscript.sql
。有没有办法做到这一点呢?这取决于你如何提升你的应用程序。如果您使用:
node app.js
你可以加上
sails.on('lifted', function yourEventHandler () {
console.log('lifted')
});
在你的app.js文件中,在line sails.lift(rc('sails'))之前
否则,您需要将其添加到配置中。最好的方法是在/config-like/config/eventhooks.js中创建新文件,内容如下:
module.exports.eventhooks = function(cb) {
sails.on('lifted', function yourEventHandler () {
console.log('lifted')
});
}
您可以在此处阅读更多内容:
var exec = require('child_process').exec;
var cmd = 'psql -d DOGHOUZ -a -f script.sql';
exec(cmd, function(error, stdout, stderr){
// command output is in stdout
});
有关在CLI中执行命令的详细信息您可以此问题的重点是如何运行CLI。我调整了我的原始问题。