title: How to connect Node.js with Cassandra?
body: <p>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.</p>
  
  <p><strong>Project Directory:</strong></p>
  
  <pre><code>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
  </code></pre>
  
  <p>Webpack is working without any problem, so the problem doesn't exist in webpack configuration.<br>
  I can insert data using cqlsh, so the problem isn't the model of data structure.</p>
  
  <p>I believe the problem is my lack of knowledge about how to use Node.js and  Cassandra together.</p>
  
  <p><strong>My process to connect Node.js with Cassandra:</strong></p>
  
  <ol>
  <li>go to build directory</li>
  <li><code>node index.js</code></li>
  <li>open localhost:3000 and find the home page, routed by express.js, displayed with no problem.</li>
  <li>go to sign-up page and submit a form</li>
  <li>error (no data inserted)</li>
  </ol>
  
  <hr>
  
  <p>I'm not sure which contact point is correct, '127.0.0.1:9042' or '127.0.0.1'</p>
  
  <pre><code>var client = new cassandra.Client({contactPoints:['127.0.0.1:9042']});
                     OR
  var client = new cassandra.Client({contactPoints:['127.0.0.1']});
  </code></pre>
  
  <p>I set my router like this.</p>
  
  <pre><code>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");
      }
    });
  });
  </code></pre>
  
  <p>Should I keep the cassandra running in the background like this?</p>
  
  <p><code>cd apache-cassandra-3.0.6</code> -> <code>cd bin</code> -> <code>./cassandra</code></p>
  
  <p>What am I missing here?</p>