Environment variables and command line usage
Recognized environment variables
The following is a list of environment variables that Roosevelt listens for.
NODE_ENV:- Set to
productionto force the app into production mode. - Set to
developmentto force the app into development mode.
- Set to
NODE_PORT: Default HTTPS port to run your app on.- Will set HTTP port instead if HTTPS is disabled.
HTTP_PORT: Default HTTP port to run your app on. Takes precedence overNODE_PORT.HTTPS_PORT: Default HTTPS port to run your app on.DISABLE_HTTP: When set totrue, the HTTP server will be disabled regardless of what is set in therooseveltConfig.DISABLE_HTTPS: When set totrue, the HTTPS server will be disabled regardless of what is set in therooseveltConfig.SWAP_HTTPS_TO_HTTP: When set totrue, the server will switch from using HTTPS to HTTP ifrooseveltConfigis currently configured to use HTTPS.MAKE_BUILD_ARTIFACTS: Lets you set Roosevelt'smakeBuildArtifactsparam via environment variable.
Environment variable precedence:
- Environment variables supersede your app's
rooseveltConfig. - Environment variables can be overridden with command line arguments.
Command line usage
Available npm scripts
Roosevelt apps created with the app generator come with the following notable npm scripts prepopulated in package.json:
npm run production: Runs the app in production mode.- Default shorthands:
npm run prodnpm run pnpm start
- Script is short for:
nodemon app.js --production-mode
- Default shorthands:
npm run development: Runs the app in development mode.- Default shorthands:
npm run devnpm run d
- Script is short for:
nodemon app.js --development-mode
- Default shorthands:
npm run production-proxy: Runs the app in production mode, but withlocalhostOnlyset to true andhostPublicset to false. This mode will make it so your app only listens to requests coming from localhost and does not serve anything in the public folder. This mode is useful when you want to host your app behind a reverse proxy from a web server like Apache or nginx and is considered a best practice for Node.js deployments.- Default shorthands:
npm run prodproxynpm run x
- Script is short for:
nodemon app.js --production-proxy-mode
- Default shorthands:
Roosevelt also ships a few commands of its own. They are available in any app that depends on Roosevelt, so you do not need a scripts entry in your package.json to use them:
npx roosevelt-generate-certs: Generates self-signed HTTPS certs for your app.- Supports command line flags
--appDir somewhere--secretsPath somewhereto override those default locations. - Writes the cert and key named by your
https.optionsparams, so it does nothing if you have not set those.
- Supports command line flags
npx roosevelt-generate-session-secret: Generates a secret key for theexpress-sessionmodule.- Supports command line flags
--appDir somewhere--secretsPath somewhereto override those default locations.
- Supports command line flags
npx roosevelt-generate-secrets: Runs both of the above.- Supports command line flags
--appDir somewhere--secretsPath somewhereto override those default locations.
- Supports command line flags
npx roosevelt-migrate-config: Converts an old JSON config into arooseveltConfig.jsfile.- Takes the app directory as an argument, and uses the current directory if you do not supply one.
Available command line arguments
node app.js --production-mode: Runs the app in production mode.- Default shorthands:
--prod-p
- Default shorthands:
node app.js --development-mode: Runs the app in development mode.- Default shorthands:
--dev-d
- Default shorthands:
node app.js --build: Only runs the build scripts and doesn't start the app.- Default shorthands:
-b
- Default shorthands:
node app.js --jsbundler=verbose: Prints verbose errors from the JS bundler to the console.- Default shorthands:
--jsb=verbose-j=verbose
- Default shorthands:
node app.js --jsbundler=verbose-file: Prints verbose errors from the JS bundler to the console as well as write a jsBundlerError.txt file to the app's root directory containing the full error.- Default shorthands:
--jsb=verbose-file-j=verbose-file
- Default shorthands:
node app.js --production-proxy-mode: Runs the app in production mode, but withlocalhostOnlyset to true andhostPublicset to false. This mode will make it so your app only listens to requests coming from localhost and does not serve anything in the public folder. This mode is useful when you want to host your app behind a reverse proxy from a web server like Apache or nginx and is considered a best practice for Node.js deployments.- Default shorthands:
--prodproxy-x
- Default shorthands:
node app.js --quieter-startup: Shows notices that repeat on every start at most once a day.- Default shorthands:
-q
- Default shorthands:
node app.js --enable-validator: Forces the HTML validator to be enabled.- Default shorthands:
--html-validator-h
- Default shorthands:
node app.js --disable-validator: Forces the HTML validator to be disabled.- Default shorthands:
--raw-r
- Default shorthands:
Overriding recognized command line flags and environment variables
You can rename the command line flags and environment variables Roosevelt listens for by passing a schema as the second argument to the Roosevelt constructor, with a "rooseveltConfig" section naming the params you want to change.
For example, by default, the mode param is set to development by --development-mode, --dev, or -d. To change it to --dev-mode or -D for that instead:
const schemaOverride = {
rooseveltConfig: { // we are overriding the Roosevelt config
mode: { // we are overriding the mode param
commandLineArg: {
development: ['--dev-mode', '-D'] // these flags now set mode to development, replacing --development-mode, --dev, and -d
}
}
}
}
const params = {} // set any Roosevelt parameters here
require('roosevelt')(params, schemaOverride).startServer()The mode param has a set of flags for each value it accepts, so they are listed by value. Only the value you list is changed: after the override above, --production-mode, --prod, and -p still set mode to production.
Environment variables are overridden the same way, using envVar. By default, the http.port param is read from the HTTP_PORT environment variable. To read it from MY_APP_PORT instead:
const schemaOverride = {
rooseveltConfig: {
http: { // we are overriding the http.port param
port: {
envVar: ['MY_APP_PORT'] // now read from MY_APP_PORT, replacing HTTP_PORT
}
}
}
}Tips:
- Once a flag or environment variable is renamed, the default no longer works. Include the default in your list if you want to keep it.
- You can also add a flag or environment variable to a param that does not have one by default, using the same syntax.
- Avoid flag names beginning with
--no-, since the command line parser treats--no-exampleas settingexampleto false rather than as a flag namedno-example.
Combining npm scripts and command line arguments
The npm scripts can be combined with the command line flags.
For example, running npm run dev -- --disable-validator will run your app in development mode and force the HTML validator to be disabled.