Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js Express for REST? Are there controllers in Express?

I'm currently developing a community (like a lightweight "social network") for a limited (local) target. This is the first project where SEO doesn't matter and where I can happily exclude no-js users. That's why I'm thinking to start the project over and write my first site that is completely build with Javascript and my first Node application for educational reasons.

Details so far:

Browser: jQuery, maybe JavaScriptMVC (there are some things I don't like about JavaScriptMVC (like the routes), maybe I write my own little MVC or do you know a better suited framework?)

Server: Node.JS, Express framework, (maybe socket.io or nowjs for further features)

I got a few questions so far. I know it's better to ask a single question but there are more or less connected:

  • Express looks really nice but I'm missing MVC. I couldn't find any project that implements mvc and is build on Express. Is there a reason for that? Routing is nice in Express but I need a way to spread code across multiple files (controllers would be the best way I guess, the application won't be small and I need it maintainable)

  • The application will be more or less completely based on AJAX (json) requests. Is Express the right framework for such applications, anyway? I think the best way to write this project is to expose a json REST api which can then be queried by the web application over AJAX and by a mobile device app (which I'm also going to write). In my opinion Express' route system is quite suited for REST. But feel free to recommend other frameworks.

like image 711
Eliasdx Avatar asked Oct 16 '11 13:10

Eliasdx


People also ask

Does Express use REST API?

Restful API is very popular and commonly used to create APIs for web-based applications. Express is a back-end web application framework of node js, and with the help of express, we can create an API very easily.

What are controllers in NodeJS?

Controllers are responsible for handling incoming requests and returning responses to the client. A controller's purpose is to receive specific requests for the application.

How does NodeJS work with Express?

Express is a node js web application framework that provides broad features for building web and mobile applications. It is used to build a single page, multipage, and hybrid web application. It's a layer built on the top of the Node js that helps manage servers and routes.


1 Answers

Have you seen Swagger? An API server available in Node.js with an automated UI Generator.

Swagger
(source: wordnik.com)

like image 50
sbstjn Avatar answered Oct 26 '22 23:10

sbstjn