balderdashy/sails · warning
Detected Sails environment of `production`, but Node environ
Error message
Detected Sails environment of `production`, but Node environment is `${process.env.NODE_ENV}`.
It is recommended that in production mode, both the Sails and Node environments be set to `production`. What it means
A warning raised in ready__ during app load: Sails' own environment (sails.config.environment) is set to 'production' but the Node process environment variable NODE_ENV is not 'production'. Sails warns because many libraries (Express middleware, ORM drivers, caching) key their behavior off NODE_ENV, and a mismatch can silently disable production optimizations or enable development behavior.
Source
Thrown at lib/app/load.js:275
*/
function ready__(cb) {
return function(err) {
if (err) {
return cb && cb(err);
}
sails.log.silly('The router & all hooks were loaded successfully.');
// If userconfig hook is turned off, still load globals.
if (sails.config.hooks && sails.config.hooks.userconfig === false ||
(sails.config.loadHooks && sails.config.loadHooks.indexOf('userconfig') === -1)) {
sails.exposeGlobals();
}
// If the Sails environment is set to "production" but the Node environment isn't,
// log a warning.
if (sails.config.environment === 'production' && process.env.NODE_ENV !== 'production') {
sails.log.warn('Detected Sails environment of `production`, but Node environment is `' + process.env.NODE_ENV + '`.\n' +
'It is recommended that in production mode, both the Sails and Node environments be set to `production`.');
}
cb && cb(null, sails);
};
}
// ██╗ ██╗ ██╗███╗ ██╗██╗ ██╗███╗ ██╗███████╗ ███████╗███╗ ██╗ ██████╗ ███████╗███████╗███████╗ ██╗
// ██╔╝ ██╔╝ ██║████╗ ██║██║ ██║████╗ ██║██╔════╝ ██╔════╝████╗ ██║ ██╔══██╗██╔════╝██╔════╝██╔════╝ ╚██╗
// ██╔╝ ██╔╝ ██║██╔██╗ ██║██║ ██║██╔██╗ ██║█████╗ █████╗ ██╔██╗ ██║ ██║ ██║█████╗ █████╗ ███████╗ ╚██╗
// ╚██╗ ██╔╝ ██║██║╚██╗██║██║ ██║██║╚██╗██║██╔══╝ ██╔══╝ ██║╚██╗██║ ██║ ██║██╔══╝ ██╔══╝ ╚════██║ ██╔╝
// ╚██╗██╔╝ ██║██║ ╚████║███████╗██║██║ ╚████║███████╗ ██║ ██║ ╚████║ ██████╔╝███████╗██║ ███████║ ██╔╝
// ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝╚══════╝╚═╝╚═╝ ╚═══╝╚══════╝ ╚═╝ ╚═╝ ╚═══╝ ╚═════╝ ╚══════╝╚═╝ ╚══════╝ ╚═╝
//
// </ inline function declarations (see note above) >
// ==============================================================================
View on GitHub (pinned to 7b76422cc2)
Solutions
- Set NODE_ENV=production in the environment before lifting (export NODE_ENV=production or configure it in pm2/systemd/Dockerfile).
- Start the app with NODE_ENV=production node app.js --prod.
- If you actually want a non-production Sails environment, change sails.config.environment accordingly so the two match.
Example fix
// before (package.json) "start": "node app.js" // after "start": "NODE_ENV=production node app.js --prod"
Defensive patterns
Strategy: validation
Validate before calling
if (process.env.NODE_ENV !== 'production') {
console.warn('NODE_ENV is not "production"; production lifts will warn. Set NODE_ENV=production.');
} Prevention
- Set NODE_ENV=production in pm2/systemd/Docker env config for every prod deployment.
- Add a preflight check or startup assertion comparing NODE_ENV with sails.config.environment.
- Document the required env vars in your deployment runbook.
When it happens
Trigger: Lifting with NODE_ENV unset or set to something other than 'production' while config/environment (or the --prod flag / NODE_ENV mapping) resolves sails.config.environment to 'production'.
Common situations: Deploying to a server where the process manager (pm2, systemd, docker) was not configured to pass NODE_ENV=production; running 'sails lift --prod' locally without exporting NODE_ENV; Docker images that set SAILS environment in config but not the OS env var.
Related errors
- E_INVALID_NODE_ENV
- rc(name): name *must* be string
- `--dev` option is deprecated: Please do not use it.
AI-assisted analysis of balderdashy/sails@7b76422cc2 (2026-09-01).
Data as JSON: /api/errors/dbaf564b5b9d37fb.
Report an issue: GitHub.