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

I am currently developing a community (for example, a lightweight "social network") for a limited (local) purpose. This is the first project in which SEO does not matter, and where I can happily exclude no-js users. That's why I'm going to start a project and write my first site, which is fully built using Javascript and my first Node application for educational reasons.

Details so far:

Browser: jQuery , maybe JavaScriptMVC (there are some things that I don’t like in JavaScriptMVC (e.g. routes), maybe I write my own MVC or do you know a more suitable structure? )

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

I have a few questions. I know that it is better to ask one question, but there are more or less related ones:

  • Express looks very good, but I'm missing MVC . I could not find any project that implements mvc and builds on Express. Is there a reason for this? Routing is good in Express, but I need a way to distribute the code across multiple files (controllers would be best, I think the application will not be small, and I need to support it)

  • 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 the json REST api , which can then be requested by the web application via AJAX and the mobile device application (which I am also going to write). In my opinion, the Express' route system is quite suitable for REST. But feel free to recommend a different framework.

+6
source share
3 answers

To answer your basic question, yes, Express has controllers. They are more similar to Sinatra (express modeled after Sinatra, not Rails). By this I mean that they are easy comparisons of the methods that you define.

Browser: jQuery, maybe JavaScriptMVC (are there some things that I don’t do, like JavaScriptMVC (like routes), maybe I write my own little MVC or do you know a more appropriate structure?

I would go with spine.js or the base. js in person.

Express looks very good, but I miss MVC. I could not find a project implementing mvc and built on Express. Is there a reason for this? Routing is good in Express, but I need a way to distribute the code across multiple files (the controllers will be the best, I believe, the application will not be small, and I need to support it)

You can distribute the files you want. I answered it here .

The application will be more or less fully based on AJAX (json) Requests. Is Express the right foundation for such applications, anyway? I think the best way to write this project is to expose the json REST api, which can then be requested by the web application over AJAX and using the mobile app (which I am also going to write). In my Routing System, Express Express Express is suitable for REST. But feel free to recommend a different framework.

I haven't created a 1 page app in node yet, but from what I can tell, almost everyone seems to use socket.io with backbone . This does not mean that you cannot, you just will find more such examples.

+4
source

Have you seen the swagger ? The API server is available in Node.js with an automatic user interface generator .

Swagger
(source: wordnik.com )

+5
source

You can check out Sails . Its structure is based on Rails.

0
source

Source: https://habr.com/ru/post/899398/


All Articles