Created
August 18, 2011 21:34
-
-
Save henriquegogo/1155295 to your computer and use it in GitHub Desktop.
Saving form in CouchDB with Node.js
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'); | |
var app = module.exports = express.createServer(); | |
var cradle = require('cradle'); | |
var db = new(cradle.Connection)().database('f2rh'); | |
// Configuration | |
app.configure(function(){ | |
app.set('views', __dirname + '/views'); | |
app.set('view engine', 'jade'); | |
app.use(express.bodyParser()); | |
app.use(express.methodOverride()); | |
app.use(app.router); | |
app.use(express.static(__dirname + '/public')); | |
}); | |
// Routes | |
app.get('/', function(req, res){ | |
res.render('index'); | |
}); | |
app.post('/add', function(req, res){ | |
db.save(req.body, function (dbErr, dbRes) { | |
res.render('success'); | |
}); | |
}); | |
app.listen(3001); | |
console.log("Express server listening on port %d", app.address().port); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment