I've been trying to connect Node.js with Cassandra on localhost for 50 years (feel like it), but haven't figured out how they work together. I would appreciate any suggestion that could lead to solution.
Project Directory:
project - app - some files
\- build - index.js, index.html, etc.(I start the server by "node index.js")
\- node_modules - some modules
\- signup - some files to be minified
\- signin - some files to be minified
\- apache-cassandra-3.0.6 - bin, conf, etc.(downloaded from tarball)
\- package.json
\- webpack.config.js
Webpack is working without any problem, so the problem doesn't exist in webpack configuration.
I can insert data using cqlsh, so the problem isn't the model of data structure.
I believe the problem is my lack of knowledge about how to use Node.js and Cassandra together.
My process to connect Node.js with Cassandra:
- go to build directory
node index.js
- open localhost:3000 and find the home page, routed by express.js, displayed with no problem.
- go to sign-up page and submit a form
- error (no data inserted)
I'm not sure which contact point is correct, '127.0.0.1:9042' or '127.0.0.1'
var client = new cassandra.Client({contactPoints:['127.0.0.1:9042']});
OR
var client = new cassandra.Client({contactPoints:['127.0.0.1']});
I set my router like this.
var router = express.Router();
var insertUser = 'INSERT INTO keyspace.users (username, create_time, email, password) VALUES (?, ?, ?, ?);';
router.get"/", function(req, res) {
res.sendFile(__dirname + '/index.html'); // This is working.
});
router.post("/signup", function(req, res) {
var username = req.body.username;
var email = req.body.email;
var password = req.body.password;
client.execute(insertUser, [username, now(), email, password],
{ prepare: true }, function(err) {
if (err) {
console.log("error"); // I receive error.
} else {
console.log("success");
}
});
});
Should I keep the cassandra running in the background like this?
cd apache-cassandra-3.0.6
-> cd bin
-> ./cassandra
What am I missing here?