This file contains 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
// install "jasmine-node" | |
// copy "specs.js" file and "lib/" directory to your project directory | |
// make "spec" dir | |
// put your spec files in "spec" directory | |
// run spec "node specs.js" | |
//an example spec file | |
var sys, zombie; | |
zombie = require('zombie'); | |
sys = require('sys'); |
This file contains 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 form = require('express-form'); | |
validate = form.validate; | |
filter = form.filter; | |
/* setup express server here */ | |
app.get('/', function(req,res){ | |
form( | |
validate('foo').required(), | |
validate('bar').required('a placeholder text for bar', 'a customize error message here') |
This file contains 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 bouncy = require('bouncy'); | |
bouncy(function(req, bounce){ | |
if (req.headers.host === 'localhost' ){ | |
console.log(req.headers.host) | |
bounce(3000); | |
} | |
else{ | |
var res = bounce.respond(); | |
res.write('error: bounce nowhere'); |
This file contains 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
formidable = require 'formidable' | |
app.configure ()-> | |
app.set 'views', __dirname + '/views' | |
app.set 'view engine', 'jade' | |
app.use (req, res, next)-> | |
contentType = req.headers['content-type'] | |
if contentType? && contentType.match /multipart\/form-data/ | |
form = new formidable.IncomingForm() | |
form.uploadDir = __dirname + '/temp' |
This file contains 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
# This snippet is inspired by edwardhotchkiss's mongoose-paginate (https://github.com/edwardhotchkiss/mongoose-paginate) | |
# and works with any methods like where, desc, poulate, etc. | |
# | |
# paginate method must be called at the end of method chains. | |
# | |
# paginate = require 'paginate' | |
# model | |
# .find() | |
# .desc("_id") | |
# .populate("some_field") |
This file contains 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
# run with 'coffee jadewatch.coffee dirname' | |
fs = require 'fs' | |
if process.argv.length < 3 | |
console.log 'Aborted: arguments are too short.' | |
return | |
else | |
child_process = require('child_process') | |
child_process.exec "ps", (err,stdout,stderr)-> | |
if stdout.indexOf("coffee jadewatch.coffee") < 0 |
This file contains 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
//ミドルウェアでやる場合 | |
app.configure(function(){ | |
//・・・(略)・・・ | |
app.use(function (req, res, next) { | |
app.locals.message = req.session.message; | |
next(); | |
}); | |
//・・・(略)・・・ | |
}); |
This file contains 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
async (callback) => { | |
const result = await asyncCode(); | |
callback(null, result) | |
} |
This file contains 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
async (callback) => { | |
try { | |
const result = await asyncCode(); | |
callback(null, result) | |
} | |
catch (e) { | |
callback(e) | |
} | |
} |
This file contains 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
async (callback) => { | |
const { err, ...result } = await asyncCode().catch(e => ({ err: e })); | |
if (err) { | |
callback(err); | |
return; | |
} | |
callback(null, result); | |
}; |
OlderNewer