Skip to content

Instantly share code, notes, and snippets.

@mjurincic
mjurincic / nginx.conf
Last active June 30, 2022 16:05 — forked from tomysmile/node-setup-pm2-nginx.md
Setup NodeJS Production with PM2, Nginx on AWS Ubuntu 16.04 server
proxy_http_version 1.1;
proxy_set_header Connection "";
https://gist.github.com/miguelmota/6912559
# The upstream module is the link between Node.js and Nginx.
# Upstream is used for proxying requests to other servers.
# All requests for / get distributed between any of the servers listed.
upstream helloworld {
# Set up multiple Node.js webservers for load balancing.
# max_fails refers to number of failed attempts
# before server is considered inactive.
@mjurincic
mjurincic / logrotate-nginx
Created September 18, 2017 08:58 — forked from aputs/logrotate-nginx
logrotate config for nginx
/var/log/nginx_*.log {
daily
compress
delaycompress
rotate 2
missingok
nocreate
sharedscripts
postrotate
test ! -f /var/run/nginx.pid || kill -USR1 `cat /var/run/nginx.pid`
@mjurincic
mjurincic / lex-stream.js
Created October 11, 2017 11:27 — forked from chrisradek/lex-stream.js
Streaming Polly Audio into Lex
var path = require('path');
var fs = require('fs');
var AWS = require('aws-sdk');
var polly = new AWS.Polly();
var lexRuntime = new AWS.LexRuntime();
async function run() {
var audioStream = polly.synthesizeSpeech({
@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 / 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);