Skip to content

Instantly share code, notes, and snippets.

View matthewrevell's full-sized avatar

Matthew Revell matthewrevell

View GitHub Profile

Role: Junior Developer Advocate

Employer: Exoscale

Location: Flexible; Berlin or Switzerland preferred

How to apply: Email your CV/resume and supporting information to [email protected]

Summary:

// Now we need to create a route to handle the POST
app.post('/', urlEncodedParser, function (req, res) {
if (!req.body) return res.sendStatus(400);
// Convert our form input into JSON ready to store in Couchbase
var jsonVersion = JSON.stringify(req.body);
// Save it into Couchbase with keyname user
bucket.upsert('user', jsonVersion, function (err, response){
if (err) {
// Run the app on port 3000
app.listen(3000, function() {
console.log('Couchbase sample app listening on port 3000');
});
// Let's create a simple home page that has a form
// The form will POST to the same location
app.get('/', function(req, res){
var html = '<form action="/" method="post">' +
'What is your name:' +
'<input type="text" name="userName" />' +
'<br>' +
'Where do you live?' +
'<input type="text" name="location" />' +
'<br>' +
// Now let's connect to Couchbase Server, assuming it's running on localhost
// and has a bucket named default
var couchbase = require('couchbase');
var cluster = new couchbase.Cluster('couchbase://127.0.0.1');
var bucket = cluster.openBucket('default');
@matthewrevell
matthewrevell / Couchbase-Node-intro-use-express.js
Last active August 29, 2015 14:18
From the "First steps with Node.js and Couchbase Server" blog post on blog.couchbase.com
// Let's use Express
var express = require('express');
var app = express();
// And bodyParser to handle our form input
var bodyParser = require('body-parser');
var urlEncodedParser = bodyParser.urlencoded({ extended: false });