Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

enter image description here

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
like image 918
user1107173 Avatar asked May 18 '15 16:05

user1107173


People also ask

What exactly is a node?

A node is a basic unit of a data structure, such as a linked list or tree data structure. Nodes contain data and also may link to other nodes. Links between nodes are often implemented by pointers.

What is node used for?

Node allows developers to write JavaScript code that runs directly in a computer process itself instead of in a browser. Node can, therefore, be used to write server-side applications with access to the operating system, file system, and everything else required to build fully-functional applications. Node.

Why is it called node?

It was merely a webserver, an alternative to Apache and other "blocking" servers. But the project soon grew beyond his initial webserver library, expanding into a framework that could be used to build, well, almost anything. So he rechristened it node.

What is a node node?

A node is a point of intersection/connection within a data communication network. In an environment where all devices are accessible through the network, these devices are all considered nodes. The individual definition of each node depends on the type of network it refers to.


2 Answers

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".

enter image description here

like image 153
Gergo Erdosi Avatar answered Oct 14 '22 07:10

Gergo Erdosi


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
like image 35
jjbskir Avatar answered Oct 14 '22 06:10

jjbskir