简体   繁体   中英

Node & Elastic Beanstalk: Set environment NODE_ENV=prod

I need to execute the following command for production environment:

NODE_ENV=production node app.js

I tried passing it as a command under Configueration:

在此输入图像描述

I get the following error in the logs:

sh: NODE_ENV=prod node app.js: command not found

I also tried:

NODE_ENV=prod  // 
error: sh: NODE_ENV=prod: command not found


NODE_ENV=prod app.js  // 
error: sh: NODE_ENV=prod app.js: command not found

What's the best way to execute the following command when launching the app on ELB:

NODE_ENV=production node app.js

You don't need to set the node command manually. Elastic Beanstalk attempts to start app.js , then server.js , and then npm start in that order. You can set the value of NODE_ENV in the "Environment Properties" section under "Configuration".

在此输入图像描述

As others have mentioned you can manually add them by going to Configuration -> Software -> Environment properties.

A second way to do this is to add a .ebextensions/environment.config file.

  1. Add the directory .ebextensions at the root of your project.
  2. Create the file environment.config within .ebextensions .
  3. Add your environment configurations.

Example of environment.config :

option_settings:
  - option_name: NODE_ENV
    value: production

You need to use the "Environment Properties" Not the node command.

在此输入图像描述

Key: NODE_ENV
Value: production

I would just set NODE_ENV in Environment Properties under the same configuration area. You can also set this in your .ebextensions config.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM