Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var express = require('express'),
driver = require('couchbase'),
routes = require('./routes')
;
dbConfiguration = {
"hosts": ["localhost:8091"],
"bucket": "ideas"
};
driver.connect(dbConfiguration, function(err, cb) {
if (err) {
throw (err)
}
var app = module.exports = express();
// Configuration
app.configure(function() {
app.set('views', __dirname + '/views');
app.engine('.html', require('ejs').renderFile);
app.set('view engine', 'html');
app.set('view options', {
layout: false
});
app.use(express.bodyParser());
app.use(express.methodOverride());
function cas(key, value, casid, cb) {
couchbase.connect(options, function(err, bucket) {
if (err) return cb(err);
// Couchbase has different methods for "set if not exists" and
// "set if not modified". This function is the common callback
// logic to be aplied after either.
function handler(err) {
if (err && err.code === couchbase.errors.keyAlreadyExists) {
return cb(kvstore.ERROR_CAS_MISMATCH);
}
cb(err);
}
if (casid === null) {
bucket.add(key, value, handler);
} else {
bucket.set(key, value, {cas: casid}, handler);
}
});
function set(key, value, cb) {
couchbase.connect(options, function(err, bucket) {
if (err) return cb(err);
bucket.set(key, value, function(err) {
cb(err);
});
});
}