S
S
Serezhka2017-09-09 01:14:33
JavaScript
Serezhka, 2017-09-09 01:14:33

What is the best way to deploy an Angular + NodeJS REST application?

Hey!
Now I have a kind of elementary application that is spinning on my computer.
It is arranged like this:
In one folder there is an angular-cli application that runs on localhost:3000
In another folder there is a "server" on nodejs that listens to localhost:3030
All this is running at the same time, and the Argular client communicates with the server via REST requests (by In essence, the server simply processes requests and puts them into the database (MySQL) .And vice versa.Now
I want to somehow correctly transfer all this to the server (I think about DigitalOcean)
How to organize it all correctly?To make it all work and
deploy.How I imagine it:
the client and the server have their own repositories (I have it on BitBucket).
As soon as the merge occurs in the master, the build is launched on the servers (I don’t know if this can be somehow connected with each other). Passing tests.
For the server, I don't know if the bundle is going there or not. But it's probably better to collect. A folder is created for the client, where statics, Angular, are placed, which will then be given to the main application URL.
That is, you need to set it all up so that, at the request of site.com , a server is launched that will return statics (which angular-cli will collect), and this statics will already make requests to the server application to take data from the database. (but at what address and port?)
So I imagine the file structure
./
-- index.js - this file listens for calls to site.comand sends the assembled bundle from /client to the browser
-- /client - here is the collected client statics
-- /server - here all processing of requests from the client takes place + user files are stored (for example, uploaded pictures)
And it is also very important that /server can receive requests not only from this client, but also external requests, from, for example, mobile applications.
In general, I would be grateful for any information on the topic, for any links, or clarification of the principles on the fingers.
Because for me now it is a very dark forest, I just don’t really understand which way to dig.
Thank you!

Answer the question

In order to leave comments, you need to log in

4 answer(s)
P
Pavel Shvedov, 2017-09-09
@Serezhka

Purely in theory:
1) You collect statics for the front into bundles
2) You run the nodejs server as a daemon using PM2
3) You install nginx, google configs how to properly force it to give statics for the front, and redirect requests through a proxy to the node server

P
Ptolemy_master, 2017-09-09
@Ptolemy_master

We have a similar stack of angular + node, running on heroku, they have a free plan. After you create an account, a special "wizard" takes you through all the stages of the deployment, it turns out quite easily, he automatically picks up and launches everything. Try it.

F
First Name Last Name, 2017-09-09
@Rockbass

1) do not serve the front using angular-cli
2) do not give statics using nodejs
3) take nginx, set the frontend build on the result, separately launch the node with api
4) profit.

S
Serezhka, 2017-09-09
@Serezhka

Thanks to all.
nginx is the key moment in the whole story, the missing link.
I will try.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question