Skip to content

Instantly share code, notes, and snippets.

@grantmichaels
grantmichaels / .gitignore
Created May 13, 2012 18:59 — forked from karmi/.gitignore
`tail -f` in Node.js and WebSockets
.DS_Store
*.log
tmp/
@grantmichaels
grantmichaels / nginx + node setup.md
Created May 13, 2012 18:58 — forked from joemccann/nginx + node setup.md
Set up nginx as a reverse proxy to node.js.

The idea is to have nginx installed and node installed. I will extend this gist to include how to install those as well, but at the moment, the following assumes you have nginx 0.7.62 and node 0.2.3 installed on a Linux distro (I used Ubuntu).

In a nutshell,

  1. nginx is used to serve static files (css, js, images, etc.)
  2. node serves all the "dynamic" stuff.

So for example, www.foo.com request comes and your css, js, and images get served thru nginx while everything else (the request for say index.html or "/") gets served through node.

  1. nginx listens on port 80.
@grantmichaels
grantmichaels / Javascript
Created May 13, 2012 18:54 — forked from necrower/Javascript
Node.js: Basic server for XMPP BOSH
var util = require('util'),
express = require('express'),
httpProxy = require('http-proxy');
var app = express.createServer(),
proxy = new httpProxy.HttpProxy();
app.configure(function() {
app.use(express.static(__dirname + "/public"));
});
@grantmichaels
grantmichaels / beacon.js
Created May 13, 2012 18:54 — forked from ruturajv/beacon.js
node.js web beacon (web bug) serving
http = require('http');
url = require('url');
http.createServer(function(req, res){
var requestURL = url.parse(req.url, true)['pathname'];
if (requestURL == '/log.gif') {
var imgHex = '47494638396101000100800000dbdfef00000021f90401000000002c00000000010001000002024401003b';
var imgBinary = new Buffer(imgHex, 'hex');
res.writeHead(200, {'Content-Type': 'image/gif' });
@grantmichaels
grantmichaels / A_dirStructure.txt
Created May 13, 2012 18:52 — forked from jfensign/A_dirStructure.txt
NodeJS and Google's Geocoder API
//Directory Structure
/app
/scripts
|-handleFormSubmit.js
/node_modules
/views
|-index.jade
/controllers
|-maps_controller.js
@grantmichaels
grantmichaels / index.js
Created May 13, 2012 18:52 — forked from jfensign/index.js
NodeJS User Registration and Authentication
//index.js
var express = require('express'),
app = module.exports = express.createServer(),
mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/nodeAuth');
//configure app
app.configure(function() {
app.set('views', __dirname + '/views');
@grantmichaels
grantmichaels / server.js
Created May 13, 2012 18:52 — forked from micahasmith/server.js
node.js google reverse geocode proxy
var http = require('http'),
q = require('querystring')
http.createServer(function (req, res) {
//create the geo long/lat path
var url=["/maps/geo?q="
,q.parse(req.url)["long"]
,","
,q.parse(req.url)["lat"]
@grantmichaels
grantmichaels / index.js
Created May 13, 2012 18:52 — forked from bnerd/index.js
Serve large files with Node.js
var libpath = require('path');
var http = require('http');
var fs = require('fs');
var url = require('url');
var bind_port = 8001;
var path = "/path/to/your/base_directory/";
http.createServer(function (request, response) {
var uri = url.parse(request.url).pathname;
var filename = libpath.join(path, uri);
@grantmichaels
grantmichaels / nodejs-example.coffee
Created May 13, 2012 18:51
Example node.js script in coffeescript.
getDoc = (title, content) ->
"""<!DOCTYPE html>
<html>
<head><title>#{title}</title></head>
<body>
<h1>#{title}</h1>
<p>#{content}</p>
</body>
</html>
"""
@grantmichaels
grantmichaels / package.json
Created May 13, 2012 18:51 — forked from akoenig/package.json
node.js talk - twitter stream reader
{
"author": "Malte Legenhausen ([email protected]), John Philip Schnake ([email protected]), André König ([email protected])",
"name": "twitter-streamer",
"description": "A little app which receives tweets in realtime!",
"version": "0.0.1",
"homepage": "http://bremen.gtugs.com",
"repository": {
"url": ""
},
"engines": {