Reputation: 352
I am working on building a social app and let's assume the app has the following features:
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 :)
Thanks for your help.
Upvotes: 0
Views: 1007
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
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
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