Skip to content

Instantly share code, notes, and snippets.

@benstuijts
benstuijts / pubsub.js
Created May 15, 2016 — forked from learncodeacademy/pubsub.js
Basic Javascript PubSub Pattern
View pubsub.js
//events - a super-basic Javascript (publish subscribe) pattern
var events = {
events: {},
on: function (eventName, fn) {
this.events[eventName] = this.events[eventName] || [];
this.events[eventName].push(fn);
},
off: function(eventName, fn) {
if (this.events[eventName]) {
@benstuijts
benstuijts / gist:8e4d7c4430423811ae398c5fb53a8827
Created May 9, 2016 — forked from learncodeacademy/gist:ebba574fc3f438c851ae
Nginx Node Frontend / Load Balancer / Static Assets Caching
View gist:8e4d7c4430423811ae398c5fb53a8827
upstream project {
server 22.22.22.2:3000;
server 22.22.22.3:3000;
server 22.22.22.5:3000;
}
server {
listen 80;
location / {
@benstuijts
benstuijts / flightplan-deploy.md
Created May 7, 2016 — forked from learncodeacademy/flightplan-deploy.md
Deploy Node.js Apps with Flightplan
View flightplan-deploy.md

##Setup your server (this would ideally be done with automated provisioning)

  • add a deploy user with password-less ssh see this gist
  • install forever npm install -g forever

##Install flightplan

  • npm install -g flightplan
  • in your project folder npm install flightplan --save-dev
  • create a flightplan.js file
@benstuijts
benstuijts / node-deploy-as-upstart-service.md
Created May 6, 2016 — forked from learncodeacademy/node-deploy-as-upstart-service.md
Deploy Node.js app on Ubuntu as Upstart Service - instead of using Forever
View node-deploy-as-upstart-service.md

Deploying a node app with Forever is great...until your server restarts unexpectedly. Then your app stops running and you have to re-deploy.

To get around this, we're going to run our node app as an Upstart service. Upstart services are great, because, once started, the system auto-restarts them if they fail, or if the server restarts.

###Step 1: Create a service for your node app

  • ssh in as root ssh root@youripaddress
  • Create a node-app.conf file in /etc/init
    IMPORTANT: whatever filename you pick is what you will use to start|stop|restart your service i.e. service node-app start