Deploy NodeJS website
Suppose you have a nodejs website that you want to run under domain api.domain.com
Make sure the two applications
NodeJSandPM2are installed on the server. See the installation guide at Application Management.Create a website with the appropriate configuration:
- Go to the server management page, click on the Sites menu in the sidebar, then click the Create Website button
- Enter the domain (e.g.,
api.domain.com) - Enter the Proxy Port — the port your nodejs application runs on, for example
3000
Install the source code for the website from git or upload it yourself. See the detailed guide at Source Code Installation. To access it, go to the site management page and click on the Source Code menu in the sidebar.
Start your nodejs application on production:
- Locally, you typically start nodejs with the command
node index.js - On production, if you have installed the PM2 application, you can use the PM2 Dashboard on the server management page to add a new process. Click the Add New button, enter the command
index.js --name my-apiand click Start - Alternatively, you can run the command manually via SSH:
pm2 start index.js --name my-api
- Locally, you typically start nodejs with the command
When you update new code, you need to restart the process:
- If using the PM2 Dashboard, click the Restart button for your process
- Or run the command:
pm2 restart my-api