Initialize the Project and Beanstalk
Initialize a express project
cd into that project
git initadd the following content to
.gitignore123node_modules/.gitignore.elasticbeanstalk/Create a repository with the
eb initcommand.1eb init --platform node.js --region us-west-2Create an environment running a sample application with the
eb createcommand.1eb create --sample node-express-envWhen environment creation completes, use the
eb opencommand to open the environment’s URL in the default browser.1eb open
Update the Application
Add the following content to
.ebextensions/nodecommand.config123option_settings:aws:elasticbeanstalk:container:nodejs:NodeCommand: "npm start"Stage the files:
12git add .git commit -m "First express app"Deploy the changes:
1eb deploy
Configure static files and add a new page to your Express Application
Add the following content to
.ebextensions/staticfiles.config123option_settings:aws:elasticbeanstalk:container:nodejs:staticfiles:/public: publicComment the following line in
app.js1// app.use(express.static(path.join(__dirname, 'public')));Add your updated files to your local repository and commit your changes.
12git add .ebextensions/ app.jsgit commit -m "Serve stylesheets statically with nginx."Add
node-express/routes/hike.js. Type the following:123456exports.index = function(req, res) {res.render('hike', {title: 'My Hiking Log'});};exports.add_hike = function(req, res) {};Update
node-express/app.jsto include three new lines.First, add the following line to add a
requirefor this route:123var express = require('express');var path = require('path');var hike = require('./routes/hike'); //add thisThen, add the following two lines to
node-express/app.jsaftervar app = express();123var app = express();app.get('/hikes', hike.index); //add thisapp.post('/add_hike', hike.add_hike); //add thisCopy
node-express/views/index.jadetonode-express/views/hike.jade.1cp views/index.jade views/hike.jadeAdd your files to the local repository, commit your changes, and deploy your updated application.
123git add .git commit -m 'Add hikes route and template'eb deploy
Clean Up
|
|