Routes Node.js with Angular.js

0

I'm starting now in the development with node and I came to the following doubt: much is talked about mean stack , but how to do the mapping of the routes using node and angular? Which one do I use to do the routes? Could you give an example? Being that with both there is the possibility of making calls of the methods. Thanks for the help!

    
asked by anonymous 09.10.2017 / 14:56

1 answer

0

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);
    }

});
    
09.10.2017 / 15:58