In MEAN Stack
Mongo
is used to write information, NodeJs
to back-end, express to help Nodejs
, and angularJs
development to front-end, ie angular will take care of the route management, and the node will only map them, to return the result according to the route, for 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);
}
});