S
S
Sergey2018-02-24 15:22:57
Angular
Sergey, 2018-02-24 15:22:57

Is it correct to use node.js as a rest api server?

I plan to write a real-time web application in Angular. This will be my first time writing a SPA application. I think how to implement api. The first option is on Symphony or yii2, I have experience in this. The second option is to write an api in node.js using Express.
I see the advantages in node.js in its asynchrony and one process, which will give advantages in a large number of connections and good request processing speed, as well as one language (js on the client and server), json does not need to be converted, and web sockets are supported out of the box .
Now to my questions.
1) What is the use of its asynchrony if, when accessing api, you need to get into the database, wait for a response from it and then return the data? (api is almost always a call to the database or cache, and the answer will still have to wait)
2) I will use a relational database (mySQL or PostgreSQL). I understand that node.js works well with MongoDb, but it doesn't work for me. Will I have driver or ORM issues and is this a good practice?
3) Should I use node.js at all in my case or go for the first option and use PHP?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
index0h, 2018-02-24
@index0h

in its asynchrony and single process

There is no advantage here, it's just marketing))
Asynchrony does not help in any way in handling a large number of connections
This is purely your job.
When transferring data to another application, it will still be necessary
You were deceived, there is no ws support out of the box either in express or in nodejs
Yes, no matter what))
Support will be difficult.
There is no point.

D
dmitrygavrish, 2018-02-25
@dmitrygavrish

1) The "benefit" of asynchrony is that the request to the database will be non-blocking, i.e. will not block code execution by the node while the database is processing the request and generating a response
2) node.js does not care what database you work with, there are many ready-made modules for the same
postgres
: ://www.npmjs.com/package/pg-promise
https://www.npmjs.com/package/pg-format
ORM:
https://www.npmjs.com/package/sequelize
3) If your goal is write an application in the minimum amount of time and with the minimum amount of effort, then write on what you understand. If you want to improve skills in another area (language / platform / ...), then you can take node.js as an option.
P.S. a node, unlike PHP, can store state throughout the life of a running process (including in a cluster), which can greatly facilitate the task of creating an application on web sockets if you need to work with timers

V
Vladimir, 2018-02-26
@Casufi

Node JS is actively used as a REST API, there are even some frameworks
https://sailsjs.com/, in addition, the relational database is quite able to hold several connections and process several requests, so I don’t understand how it can interfere with asynchrony.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question