This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'), | |
url = require('url'), | |
_ = require('underscore'), | |
elastical = require('elastical'); | |
var client = new elastical.Client(); | |
if (process.argv.length < 3) { | |
console.log('Port number is required'); | |
return; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require("express"); | |
var sys = require("sys"); | |
var io = require("socket.io"); | |
var ChatServer = {}; | |
ChatServer.members = {}; | |
ChatServer.publish = function(client, data) { | |
if (client in ChatServer.members) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
NODE_VERSION=0.4.12 | |
NODE_FILE=node-v$NODE_VERSION | |
MY_USER=mashihua | |
REDIS_VERSION=2.0.3 | |
apt-get update | |
apt-get install -y build-essential git-core nginx libssl-dev pkg-config | |
wget http://nodejs.org/dist/$NODE_FILE.tar.gz |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sqlite3 = require('sqlite3').verbose(); | |
var db = new sqlite3.Database('guy.sqlite'); //':memory:' | |
db.serialize(function() { | |
db.get("SELECT name FROM sqlite_master WHERE type='table' AND name='lorem'", function(error, row) { | |
if (row !== undefined) { | |
console.log("table exists. cleaning existing records"); | |
db.run("DELETE FROM lorem", function(error) { | |
if (error) | |
console.log(error); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
NODE_VERSION=0.4.10 | |
NPM_VERSION=1.0.22 | |
sudo apt-get update | |
sudo apt-get install -y build-essential git-core nginx libssl-dev pkg-config curl | |
# Install node | |
mkdir -p $HOME/local/node | |
git clone git://github.com/joyent/node.git |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'); | |
var host = "search.twitter.com", | |
requestUrl = '/search.json?q=nodejs', | |
twitter = http.createClient(80, host), | |
request = twitter.request('GET', requestUrl, | |
{ "host" : host, "User-Agent" : "Nodejs HTTP Client" }); | |
request.on('response', function(response){ | |
var body = ''; | |
response.setEncoding("utf8"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require('request'), http = require('http'), $ = require('jquery'), querystring = require('querystring'); | |
http.createServer(function (req, res) { | |
var q = querystring.parse(req.url); | |
var locations = {'deurne': 0, 'machelen': 1, 'alleur': 2, 'eke': 3, 'sint-pieters-leeuw': 4}; | |
request({uri: 'http://www.makro.be/Content/assortiment/benzinestation/benzineprijzen/1/index.jsp?stat=' + locations[q.l]}, function (error, response, body) { | |
res.writeHead(200, {'Content-Type': 'text/xml'}); | |
var fuel_types = ['diesel', 'eurosuper', 'superplus']; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A very basic web server in node.js | |
// Stolen from: Node.js for Front-End Developers by Garann Means (p. 9-10) | |
var port = 8000; | |
var serverUrl = "127.0.0.1"; | |
var http = require("http"); | |
var path = require("path"); | |
var fs = require("fs"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'), | |
url = require('url'), | |
qs = require('querystring'); | |
var paths = { | |
'__default__': function (req, res) { | |
console.log('noop'); | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.end(); | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Module dependencies. | |
*/ | |
var express = require('express') | |
, routes = require('./routes') | |
, stylus = require('stylus') | |
, util = require('util') | |
//, form = require('connect-form') |