Exposing the data from Cassandra DB running in an instance to external world by running a NodeJS server. The tools, frameworks and technologies involved are:
- Cassandra - Contains our data!
- NodeJS - Server-side scripting Language!
- ExpressJS - Framework for building API!
- Postman - To test the API!
Initially check the version of node and npm.
$ npm --version
$ node --versionThis package requires Node.js and ExpressJS to function. Initialize the npm module using $ npm init command.
Install the dependencies and devDependencies.
$ npm install -g express
$ npm install -g nodemon
$ npm install -g cassandra-driverCheck the installation of the packages using $ ls node_modules #(dir node_modules for windows)command
- Create the
main.jsfile
$ vi main.js -
Use this link in a straight-forward approach. For asynchronous calls use this link
-
Replace the keyspace
davekeyspace1with your keyspace -
Optional Customization :
- contactPoints (127.0.0.1)
- Cassandra execute query (Select * from davetable)
- Port number (3000)
-
Run the
$ nodemon --inspect main.jscommand to start the server -
Try hitting the endpoint
youripaddress:port. eg.,54.54.204.204:3000
The output is in json.
[{"emp_id":1,"emp_city":"Pondi","emp_name":"Lego"},
{"emp_id":2,"emp_city":"Tripati","emp_name":"Dhana"},
{"emp_id":3,"emp_city":"Trichi","emp_name":"Dave"}]- If port number is occupied, then try
$ killall -9 node - To check if API works in local instance, try
$ curl localhost:3000
Some sample visualization achieved using the JSON (Built using Highchart)