In MEAN Stack
Mongo
is used to save information, NodeJs
to the back-end, express to help in the development Nodejs
, and angularJs
to the front-end, that is, the Angularjs will take care of the management of the routes, and the Node will only map them, to return the result according to the route, example...
Build with express
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
app.use(express.static(__dirname + '/www'));
app.use(bodyParser());
var porta = 3412;
app.listen(process.env.PORT || porta, function(){
console.log('Servidor online porta ' + porta);
});
Mapping the routes
app.get('/nomeDaRota', function(req, res) {
res.json(restaurantes);
});
app.get('/nomeDaRota/:id', function(req, res) {
var id = req.params.id;
for (var i = 0; i < objeto.length; i++) {
if (objeto[i].id === parseInt(id)) {
var peg = objeto[i];
}
}
if (typeof peg == "undefined") {
res.json('Erro');
}else{
res.json(peg);
}
});