A
A
angelzzz2018-09-26 12:50:59
Node.js
angelzzz, 2018-09-26 12:50:59

How to move a nodejs project to DigitalOcean hosting?

You need to upload a project written in nodejs to DigitalOcean hosting.
I am doing this for the first time.
1. Created a droplet, configured nginx, firewall and installed node according to DO tutorials. Connected via filezilla.
2. Do I just upload all the files that I have in the local project that I just run "npm start" to the var/www/projectname/html folder? Or load everything without node_modules and then reinstall them on the server via npm install? In general, how is it done correctly?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Fedor Rychkov, 2018-09-26
@angelzzz

Good solution if you have a nodejs backend.. :
Support all previous answers about git, but -> Set up a private repository in bitbucket. Get a .gitignore file (be sure to write node_modules there).
Next ->
Look towards pm2, it's an application uptime manager. Find a tutorial for setting up pm2 in your project, be sure to install the pm2-auto-pull plugin and set up your server analytics (using keymetrics - this is configured via the console using the same pm2 *) All this is done via the console (Look for a decent tutorial).
After the project is in bitbucket and there is pm2 and pm2-auto-pull, you can clone your repository on the server, raise pm2 and the plugin for auto-deploy from bitbucket. And now your server can knock on git itself and update from a branch (for example, master).
Either clone the backing to the server and update it manually when you need to, which is also a good option.
On the server, you should have the same node that you have in your local environment (to definitely run the project without errors)
Something like this.

E
Eugene, 2018-09-26
@immaculate

There is no single right way, but your way is definitely wrong. Copying node_modulesfrom a local machine to a hosting is a fundamentally wrong approach.
For good, you need to start with one of two things:
1) The code is in the GitHub/BitBucket/GitLab repository. With each deployment on the DO server, git pull, npm install
2) The code in the Git repository is manually executed. The ansible script that installs node, npm on the droplet, executes git pull, npm install
From one of these options, you can already dance further.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question