Routes with Angularjs and Node.js

Asked

Viewed 393 times

0

I learned a little about Angularjs and now I’m starting with Node.js and some doubts have arisen. With Angular I use $routeProvider to create the routes and navigate between the pages as single page application, Node also managed to use the routes, but the question arose of how to use the two or if, using angular and Node, I must use the routes in one or the other.

I’ve read a lot of things and from what I’ve seen, I should use the routes through Ode only, that’s right?

2 answers

2


War, the $routeProvider is used only on the front end and serves to navigate between pages. With it you can define the controller and layout of each page.

nodejs is a server (backend). The routes you create in Express are REST and you can make requests for these services via angular $http.

1

It is right to use only Node,

With express you will probably want to capture all the requests and send to your example index.html:

app = express();
app.use(app.router);
app.use(function(req, res) {
  res.sendfile(__dirname + '/public/index.html');
});

source

  • Got it. So ngRoute would only be for web pages or applications that don’t use Node and express? Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.