{"record":{"id":"08699d01056f9329","repo":"balderdashy/sails","slug":"e-invalid-node-env","errorCode":"E_INVALID_NODE_ENV","errorMessage":"When the Sails environment is set to \"production\", NODE_ENV must also be set to \"production\" (but it was set to \"' + process.env.NODE_ENV + '\" instead).","messagePattern":"When the Sails environment is set to \"production\", NODE_ENV must also be set to \"production\" \\(but it was set to \"' \\+ process\\.env\\.NODE_ENV \\+ '\" instead\\)\\.","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/app/load.js","lineNumber":248,"sourceCode":"\n  function verifyEnvironment() {\n    // At this point, the Sails environment is set to its final value,\n    // whether it came from the command line or a config file. So we\n    // can now compare it to the NODE_ENV environment variable and\n    // act accordingly.  This may involve changing NODE_ENV to \"production\",\n    // which we want to do as early as possible since dependencies might\n    // be relying on that value.\n\n    // If the Sails environment is production, but NODE_ENV is undefined,\n    // log a warning and change NODE_ENV to \"production\".\n    if (sails.config.environment === 'production' && process.env.NODE_ENV !== 'production' ) {\n      if (_.isUndefined(process.env.NODE_ENV)) {\n        sails.log.debug('Detected Sails environment is \"production\", but NODE_ENV is `undefined`.');\n        sails.log.debug('Automatically setting the NODE_ENV environment variable to \"production\".');\n        sails.log.debug();\n        process.env.NODE_ENV = 'production';\n      } else {\n        throw flaverr({ name: 'userError', code: 'E_INVALID_NODE_ENV' }, new Error('When the Sails environment is set to \"production\", NODE_ENV must also be set to \"production\" (but it was set to \"' + process.env.NODE_ENV + '\" instead).'));\n      }\n    }\n  }\n\n  /**\n   * Returns function which is fired when Sails is ready to go\n   *\n   * @api private\n   */\n  function ready__(cb) {\n    return function(err) {\n      if (err) {\n        return cb && cb(err);\n      }\n\n      sails.log.silly('The router & all hooks were loaded successfully.');\n\n      // If userconfig hook is turned off, still load globals.","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/balderdashy/sails/blob/7b76422cc27823df033572bdda5c4910a68b697f/lib/app/load.js#L230-L266","documentation":"When Sails' own environment is set to \"production\", the NODE_ENV process variable must match. If NODE_ENV is unset Sails fixes it automatically, but if it is set to anything other than \"production\" the load fails with code E_INVALID_NODE_ENV (verifyEnvironment in lib/app/load.js).","triggerScenarios":"Starting sails with `sails_environment=production` (config or env) while NODE_ENV is e.g. \"development\", \"staging\", or any non-production string.","commonSituations":"Hardcoding environment: 'production' in config/local.js while running with NODE_ENV=development locally; CI/production containers where NODE_ENV defaults to development; deploying to hosts that set NODE_ENV themselves.","solutions":["Run the app with NODE_ENV=production when the Sails environment is production (e.g. `NODE_ENV=production node app.js`).","Unset the conflicting NODE_ENV so Sails can auto-set it to production.","Set both consistently in your deployment platform's env settings or start script.","Stop hardcoding environment in config files; derive both from NODE_ENV."],"exampleFix":"// before (package.json)\n\"start\": \"node app.js\"  // NODE_ENV=development from host\n// after\n\"start\": \"NODE_ENV=production node app.js\"","handlingStrategy":"validation","validationCode":"if (process.env.sails_environment === 'production' || config.environment === 'production') { if (!process.env.NODE_ENV) { process.env.NODE_ENV = 'production'; } else if (process.env.NODE_ENV !== 'production') { throw new Error('NODE_ENV must be production'); } }","typeGuard":null,"tryCatchPattern":"try { await sails.lift(); } catch (e) { if (e.code === 'E_INVALID_NODE_ENV') { console.error('Set NODE_ENV=production before lifting'); process.exit(1); } throw e; }","preventionTips":["Always set NODE_ENV explicitly in production deployments.","Don't hardcode environment in config/local.js.","Keep Sails environment and NODE_ENV driven from one source of truth (NODE_ENV).","Add a deploy-time env check in CI/CD before lift."],"tags":["sails","node-env","environment","production","configuration"],"backgroundTag":"node-env-mismatch","analyzedSha":"7b76422cc27823df033572bdda5c4910a68b697f","analyzedAt":"2026-09-01T04:01:57.104Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}