I need to run PostgreSQL script right after lifting my application. For example, I need to execute this command: psql -d DOGHOUZ -a -f script.sql
from the app. Is there a way how to do that?
Asked
Active
Viewed 1,458 times
2

dim0_0n
- 2,404
- 5
- 27
- 46
1 Answers
6
It depends how you lift your app. If you use:
node app.js
you can add
sails.on('lifted', function yourEventHandler () {
console.log('lifted')
});
in your app.js file before line sails.lift(rc('sails'));
Otherwise you need to add that into configuration. Best approach would be creating new file in /config like /config/eventhooks.js with content:
module.exports.eventhooks = function(cb) {
sails.on('lifted', function yourEventHandler () {
console.log('lifted')
});
}
You can read more here:
Edit 1
To execute CLI commands just do:
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
});
More about executing commands in CLI you can read here
-
The main emphasis of this question is how run CLI. I adjusted my origin question. – dim0_0n Apr 07 '16 at 13:40