Answer the question
In order to leave comments, you need to log in
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
in its asynchrony and single process
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question