- TodoMVC++ Github Repo: TodoMVC++ is the companion application for Zero to Production with Node.
- The Elastic Beanstalk Command Line Interface (EB CLI): Command line interface for Elastic Beanstalk.
- ngrok: Secure tunnels to localhost.
- Locust: An open source load testing tool.
- Rollbar: Error tracking Service for the Server side.
- TrackJS: Error tracking on the Client side.
- Google Analytics
- universal-analytics: A node module for Google's Universal Analytics tracking.
❯ npm install
On a Mac, the easiest path to installing Postgres
is Homebrew
:
❯ brew update
❯ brew install postgresql
Start Postgres
:
❯ pg_ctl -D /usr/local/var/postgres start
Create the databases for the project and apply the migrations:
❯ createdb todos
❯ createdb todos-test
❯ npm run migrate
If Postgres
is not installed locally, you can setup a free instance as follows:
- Visit
ElephantSQL
. - Login and setup a free tiny turtle instance.
- Goto Details and copy the
Postgres
url.
Create a config/user.js
file and change the value of config.database
accordingly:
'use strict'
let config = {}
config.databaseUrl = 'postgres://whatever:fromElephantSQLWeb'
module.exports = config
Migrate the database:
❯ npm run migrate
❯ NODE_ENV=development
❯ npm run grunt collect_static
❯ npm run grunt
❯ NODE_ENV=production
❯ npm run grunt collect_static
❯ npm start
index.js
const express = require('express')
const createUserMiddleware = require('./middleware')
const app = express()
app.use(createUserMiddleware('Dave'))
app.get('/hal', (req, res) =>
res.send(`Just what do you think you are doing, ${req.user.name}?`)
)
app.listen(4000)
middleware.js
const createUser = username =>
(req, res, next) => {
req.user = { name: username }
next()
}
module.exports = createUser
- Run it with
❯ node index.js
. - Hit it at
http://localhost:4000/hal
. - Get
Just what do you think you are doing, Dave?
.
EB -> Elastic BeanStalk. RDS -> Relational Database Service.
One possible pipeline to get a Node App deployed on AWS using:
- EB:
- Elastic Load Balancer.
- EB Environment.
- Provisions EC2 instances within an AutoScaled Group.
- RDS database on the backend.
- Select an AWS Region.
- Create a user with sufficient permissions.
- Create an EB environment (will be added to a security group).
- Fully functional execution environment for your App.
- Typically you'll have multiple environments:
- Development
- Staging
- Production
- Create an RDS instance (add to same EB security group).
- Our EB environment instances can connect to our RDS instance.
- The outside world can't directly connect to out RDS instance.
- Configure security group to allow incoming connections to Postgres.
- Deploy application version.
❯ brew install aws-elasticbeanstalk
❯ eb init
❯ eb create
❯ eb deploy
- If you configure your RDS instance to NOT accept traffic from the outside, then it's not the end of the world to have the DB Connection String as an Environment Variable (accessible through the console UI).
- But there's an ever better way to store secure credentials in a S3 bucket (in an XML or JSON file) and then load them into the system environment (not accessible through the console UI).
Install libevent (dependency for gevent):
❯ brew install libevent
Install locust:
❯ pip install locustio
Locust opens a new file per new simutaled user, when testing.
- 1000 opened files means 1000 concurrent users.
Raise the number of open files to 1000, in the context of the current terminal session:
❯ ulimit -n 1000
❯ npm install --save rollbar
const express = require('express')
// Basic Rollbar Usage
const rollbar = require('rollbar')
let app = express()
// Rollback Middleware
app.use(rollbar.errorHandler('TYPE-YOUR-KEY-HERE'))
// Export Express webapp instance
module.exports = app