Hello,
I followed a couchbase tutorial and modified it slightly to make it compatible with the newest Couchbase SDK version:
// == basic requirements
var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var logger = require('morgan');
var bcrypt = require('bcryptjs');
var uuid = require('uuid');
var fs = require('fs');
var ejs = require('ejs');
var keys = JSON.parse(fs.readFileSync('keys.json','utf8'));
// == init couchbase connector
var couchbase = require('couchbase');
var cluster = new couchbase.Cluster('couchbase://127.0.0.1',{
username: keys.couchbase.user,
password: keys.couchbase.pass
});
var bucket = cluster.bucket('TestApp').defaultCollection();
var sqlQuery = couchbase.N1q1Query;
// == routes
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var app = express();
if (app) console.log("Server started...");
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(__dirname + '/views'));
app.use(logger('dev'));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', indexRouter);
app.use('/users', usersRouter);
app.post('/register', (req,res) => {
if (!req.body.email) {
return res.status(401).send({ "message" : "An email is required." });
}
else if (!req.body.password) {
return res.status(401).send({ "message" : "A password is required." });
}
else if (req.body.password != req.body.passwordConf) {
return res.status(401).send({ "message" : "Your two passwords are different." });
}
var user_id = uuid.v4();
var account = {
type : "account" ,
pid: user_id ,
email: req.body.email ,
password: bcrypt.hashSync(req.body.password, 10)
};
var profile = req.body;
profile.type = "profile";
delete profile.password;
bucket.insert(user_id,profile, (err, result) => {
if (err) { console.log(err); return res.status(500).send(err); }
bucket.insert(req.body.email, account, (err, result) => {
if (err) {
bucket.remove(user_id);
console.log(err);
return res.status(500).send(err);
}
res.send(result);
});
});
});
All of the code in the endpoint functions well, until the first bucket command, in which the application crashes with a Segfault. It doesn’t return an error object – it completely crashes, so I have no stack traces, and the callback doesn’t execute.
But I do know it crashes on the bucket.insert command (which is really bucket.defaultCollection().insert). I created the cluster and ran the CREATE INDEX query from the tutorial. That’s about all I did. This error also happens on my other machine, separate database, same commands and code.
Using:
node v. 11.10.0
npm couchbase v.3.0.0-alpha.1
operating systems Ubuntu and Manjaro.
Also, I’ve tried taking a look into some of the source and running an insert command outside of the endpoint, executing immediately upon starting the server. It gave me an error mentioning waiting for bootstrap/connect to finish, and not a flat out Segmentation fault.