Skip to content

Instantly share code, notes, and snippets.

@mjurincic
mjurincic / elb-nodejs-ws.md
Created December 7, 2017 14:30 — forked from obolton/elb-nodejs-ws.md
Configuring an AWS Elastic Load Balancer for a Node.js application using WebSockets on EC2

AWS ELB with Node.js and WebSockets

This assumes that:

  • You are using Nginx.
  • You want to accept incoming connections on port 80.
  • Your Node.js app is listening on port 3000.
  • You want to be able to connect to your Node.js instance directly as well as via the load balancer.

####1. Create load balancer

@mjurincic
mjurincic / app-koa.js
Created December 7, 2017 15:04 — forked from Unitech/app-koa.js
Node.js Load Balancers Benchmark: HAProxy vs Nginx vs PM2
const Koa = require('koa');
const app = new Koa();
app.use(ctx => {
ctx.body = 'Hello World';
});
var listener = app.listen(process.env.PORT || 3000, () => {
console.log(`Listening on port ${listener.address().port}`);
});
@mjurincic
mjurincic / README.md
Created December 12, 2017 16:04
Configure Nginx as a web server and reverse proxy for Nodejs application on AWS Ubuntu 16.04 server

Configure Nginx as a web server and reverse proxy for Nodejs application on AWS Ubuntu 16.04 server Introduction Nginx was created in response to C10k challenge for handling at least 10,000 simultaneous client connections on a single server. Nginx uses asynchronous, event-driven architecture to handle these massive amount of connections. This architecture makes handling high and fluctuating loads much more predictable in terms of RAM usage, CPU usage, and latency. Nginx can be used as web server, reverse proxy, load balancer and HTTP cache.

Image Credits Installing Nginx on AWS ec2 instance with Ubuntu 16.04 $ sudo apt-get update && sudo apt-get upgrade -y $ sudo apt-get install nginx -y Setup Nginx

@mjurincic
mjurincic / publish_gitbook.sh
Created January 25, 2018 22:40 — forked from SangsooNam/publish_gitbook.sh
Publish GitBook to Github Pages(gh-pages)
# install the plugins and build the static site
gitbook install && gitbook build
# checkout to the gh-pages branch
git checkout gh-pages
# pull the latest updates
git pull origin gh-pages --rebase
# copy the static site files into the current directory.
const http = require('http');
const memwatch = require('memwatch-next');
const heapdump = require('heapdump');
var server = http.createServer((req, res) => {
for (var i=0; i<1000; i++) {
server.on('request', function leakyfunc() {});
}
res.end('Hello World\n');
@mjurincic
mjurincic / gitflowrebasing.md
Created February 15, 2018 13:38 — forked from markreid/gitflowrebasing.md
git flow with rebasing
@mjurincic
mjurincic / footgun.md
Created February 23, 2018 09:50 — forked from Rich-Harris/footgun.md
Top-level `await` is a footgun
@mjurincic
mjurincic / logging.js
Created April 3, 2018 18:06
A simple node module that makes console.log/error/warn/debug statements log through winston (simply include at the beginning of your app)
'use strict';
var util = require('util'),
winston = require('winston'),
logger = new winston.Logger(),
production = (process.env.NODE_ENV || '').toLowerCase() === 'production';
module.exports = {
middleware: function(req, res, next){
console.info(req.method, req.url, res.statusCode);
@mjurincic
mjurincic / apps.js
Created May 24, 2018 12:12 — forked from eliOcs/apps.js
Express and Handlebars
/*jslint node: true */
"use strict";
var express = require("express"),
consolidate = require("consolidate"),
Handlebars = require("handlebars"),
fs = require("fs");
var app = express();
@mjurincic
mjurincic / duplicate-select-list.html
Created May 30, 2018 15:27 — forked from sleepdeprecation/duplicate-select-list.html
Duplicate a select list using jQuery
<!DOCTYPE html>
<html>
<head>
<title>Duplicate a select list using jQuery</title>
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="selectScript.js"></script>
</head>
<body>
<div id="d1">