Abhilash Shamsunder
Abhilash Shamsunder

Reputation: 352

Nodejs rest api & database recommendations

I am working on building a social app and let's assume the app has the following features:

  1. User feed
  2. Friend request, Connections.
  3. Likes
  4. Comments

For the same, I am building a REST API using nodejs and my experience with nodejs is limited. I have spent alot of time researching and I found information in bits and pieces. I am looking forward to hear some suggestions from the experts :)

  1. I am planning to use NoSQL graph database(Neo4j, OrientDB). Is this a good choice. or are their better options or should I go with a relational database like mysql?
  2. For CRUD operations, I was thinking sailjs. (I was planning on using yeoman, but there are no generators for Sails yet). Thoughts/Recommendations?

Thanks for your help.

Upvotes: 0

Views: 1007

Answers (3)

Parth
Parth

Reputation: 74

sailsjs with couchdb and angular js would be my recommendation.you can refer couchdb vs mongodb also refer this to see the advantages & features of sails. You can use nano along with couchdb-lucene to get the most out of couch db.

Upvotes: 0

Shaikh Shahid
Shaikh Shahid

Reputation: 1215

Please refer this code.

Server.js

var express = require("express");
var mysql   = require("mysql");
var bodyParser  = require("body-parser");
var rest = require("./REST.js");
var app  = express();

function REST(){
    var self = this;
    self.connect_to_mysql();
}

REST.prototype.connect_to_mysql = function() {
    var self = this;
    var pool      =    mysql.createPool({
        connectionLimit : 100,
        host     : 'localhost',
        user     : 'root',
        password : '',
        database : 'restful_api_demo',
        debug    :  false
    });
    pool.getConnection(function(err,connection){
        if(err) {
          self.stop(err);
        } else {
          self.configureExpress(connection);
        }
    });
}

REST.prototype.configureExpress = function(connection) {
      var self = this;
      app.use(bodyParser.urlencoded({ extended: true }));
      app.use(bodyParser.json());
      var router = express.Router();
      app.use('/api', router);
      var rest_router = new rest(router,connection);
      self.start_server();
}

REST.prototype.start_server = function() {
      app.listen(3000,function(){
          console.log("All right ! I am alive at Port 3000.");
      });
}

REST.prototype.stop = function(err) {
    console.log("ISSUE WITH MYSQL \n" + err);
    process.exit(1);
}

new REST(); // Instantiate clas

Here is REST.js

function REST_ROUTER(router,connection) {
    var self = this;
    self.handle_routes(router,connection);
}

REST_ROUTER.prototype.handle_routes = function(router,connection) {
    router.get("/",function(req,res){
        res.json({"Message" : "Hello World !"});
    })
}

module.exports = REST_ROUTER;

Link : http://codeforgeek.com/2015/03/restful-api-node-and-express-4/

Upvotes: 0

MattDionis
MattDionis

Reputation: 3616

I am a huge fan of the MEAN Stack. MongoDB for the database, ExpressJS as a Node framework, AngularJS for the front-end, and NodeJS on the server. With that said, the applications I have built work well with MongoDB's NoSQL structure. For a social network a relational database may make much more sense and save you some headaches down the road. Here is a thorough article explaining why.

Upvotes: 0

Related Questions