Setting Up your Node.js Development Environment
Set up a Node.js development environment to test your application locally prior to deploying it to AWS Elastic Beanstalk. This topic outlines development environment setup steps and links to installation pages for useful tools.
For common setup steps and tools that apply to all languages, see Configuring Your Development Machine for Use with AWS Elastic Beanstalk
Installing Node.js
Install Node.js to run Node.js applications locally. If you don't have a preference, get the latest version supported by Elastic Beanstalk. See Node.js in the AWS Elastic Beanstalk Platforms document for a list of supported versions.
Download Node.js at nodejs.org.
Note
When support for the version of Node.js that you are using is removed from the platform configuration, you must change or remove the version setting prior to doing a platform upgrade. This may occur when a security vulnerability is identified for one or more versions of Node.js
When this occurs, attempting to upgrade to a new version of the platform that does not support the configured NodeVersion fails. To avoid needing to create a new environment, change the NodeVersion configuration option to a version that is supported by both the old configuration version and the new one, or remove the option setting, and then perform the platform upgrade.
Installing npm
Node.js uses the npm package manager to helps you install tools and frameworks for use in your application. Download npm at npmjs.com.
Installing the AWS SDK for Node.js
If you need to manage AWS resources from within your application, install the AWS SDK for JavaScript in Node.js. Install the SDK with npm:
$
npm install aws-sdk
Visit the AWS SDK for JavaScript in Node.js homepage for more information.
Installing Express
Express is a web application framework that runs on Node.js. To use it, set up Express and create the project structure. The following walks you through setting up Express on a Linux operating system.
Note
Depending on your permission level to system directories, you might need to prefix
some of these commands with sudo
.
To set up your Express development environment on your local computer
-
Create a directory for your Express application.
~$
mkdir node-express
~$cd node-express
-
Install Express globally so that you have access to the
express
command.~/node-express$
npm install -g express-generator
-
Depending on your operating system, you may need to set your path to run the
express
command. If you need to set your path, use the output from the previous step when you installed Express. The following is an example.~/node-express$
export PATH=$PATH:/usr/local/share/npm/bin/express
-
Run the
express
command. This generatespackage.json
,app.js
, and a few directories.~/node-express$
express
When prompted if you want to continue, type
y
. -
Set up local dependencies.
~/node-express$
npm install
-
Verify it works.
~/node-express$
npm start
You should see output similar to the following:
> nodejs@0.0.0 start /home/local/user/node-express > node ./bin/www
The server runs on port 3000 by default. To test it, run
curl http://localhost:3000
in another terminal, or open a browser on the local computer and go tohttp://localhost:3000
.Press Ctrl+C to stop the server.