Milkncookiez Milkncookiez - 1 year ago 84
Node.js Question

Sails app doesn't lower

In a custom script, I'm lifting Sails, doing some stuff, then calling

but the app doesn't stop. No error is returned either...

const Sails = require('sails')
, rc = require('rc');

function run() {
Sails.lift(rc('sails', {process: 'manual'}), (err, server)=> {
if (err) {

// ... do some stuff

Sails.lower({}, (err)=> {
console.log('ERROR', err);
return true;

The app just continues running. No error is returned from
and it doesn't have a callback result by default. I debugged in the
file itself and turns out that that code isn't even reached...

I think the problem is that
returns a callback, but my script doesn't accept one, so how do I manage this case?

Answer Source

So, actually the app was getting lowered and all services (HTTP, socket, etc.) were shut down, but the process itself continued running. process.exit() was the solution. So, I first gracefully lower all services and then terminate the process:

      Sails.lower({}, (err) => {
        if (err) {
          log.error('An error occurred while shutting the server down.');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download