Running a Node.js project on your CapRover KVM VPS

Procédure

1. Requirements on the VPS side

  • CapRover template already configured

  • A root domain (e.g. vpsXXXX.serveur-vps.net) pointing to the IP of the machine and HTTPS enabled.

2. Install the CapRover CLI tool locally

⌨ Command
npm install -g caprover

This CLI tool centralises connection to the server, creation of apps and deployment on CapRover.

3. Create a Node.js skeleton

⌨ Command
mkdir my-app && cd my-app && npm init -y && npm i express

Create a minimal index.js file :

Code
const express = require('express') const app = express() const port = 3000 app.get('/', (req, res) => { res.send('CapRover + Node + LWS = ❤️') }) app.listen(port, () => { console.log(`Example app listening on port ${port}`) })

Don't forget to modify the package.json in order to define a start command, your file should look like this :

Code
{ "name": "my-app", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "start": "node index.js" }, "keywords": [], "author": "", "license": "ISC", "dependencies": { "express": "^5.1.0" } }


4. Add the captain-definition file

To the root of the repo (next to package.json) :

Code
{ "schemaVersion": 2, "templateId": "node/20" }

  • schemaVersion remains at 2.

  • In templateId, you can put any official version of Node available on Docker Hub; here we choose 20.

No need to write a Dockerfile as long as your application is simple.

5. Initialise the Git repository

⌨ Command
git init; git add .; git commit -m "First version."

6. Connect to your CapRover server

⌨ Command
caprover login

Follow the questions :

CapRover machine URL address: https: //captain.vpsXXXXXX.serveur-vps.net

CapRover machine password: admin password

CapRover machine name: captain-01 (the name you give to the local machine you are working on)

The session is now saved locally!

Documentation.

7. Create the application on CapRover

Via the "Create a new App" web interface.
Give it a short name (e.g. my-app); Click on your application, and set the HTTP container port to "3000". CapRover will redirect the PORT that your code listens to to port 80.

Running a Node.js project on your CapRover KVM VPS

Running a Node.js project on your CapRover KVM VPS

8. Deploy in one command

⌨ Command
caprover deploy

Select :

  • the server (if several)

  • the app(my-app)

  • the branch(master/main)

  • Y

The CLI :

  1. zips your sources,

  2. sends the archive,

  3. builds the image,

  4. starts the container and shows the caprover.com logs.

9. Enable HTTPS (optional but recommended)

  • In the CapRover interface: my-app → HTTP settings → Enable HTTPS (Let's Encrypt, automatic).

  • Open https://my-app.vpsXXXXX.serveur-vps.net (or the URL provided).

10. Deploy again (after each commit)

⌨ Command
git add . git commit -m "New feature" caprover deploy -d

( the -d option means: reuse the previous options)

Conclusion

You now know how to :

  • Prepare your VPS with a CapRover template and a root domain pointing to the machine's IP address.
  • Install the CapRover CLI tool locally to centralise connection and deployment.
  • Create a Node.js application skeleton and prepare your package.json file.
  • Add the captain-definition file to define the version of Node.js used.
  • Initialise a Git repository and make your first commit.
  • Connect to your CapRover server and save the session locally.
  • Create the application on CapRover and configure the HTTP port.
  • Deploy your application in one command using the CapRover CLI.
  • Enable HTTPS to secure your application (optional but recommended).
  • Deploy your application again after each commit to update your website.

🚀 By following these steps, you are now able to launch a Node.js application on a VPS server using CapRover, a powerful tool that simplifies container orchestration. You can now take advantage of the flexibility and speed of continuous deployment for your web projects.

Thank you for reading all the way through! If you have any questions, feedback or just want to share your experience with CapRover, please feel free to leave a comment below 👇. Your feedback is valuable and helps us improve our content! 😊

help.lws.net/a/1952
Was this article helpful?

Yes

No

Read 6 098 times

Thank you! Feel free to ask questions about our documentation if you would like more information, and help us improve it.

Similar articles

A question about this article?

Ask the LWS team and the community. Answers are published after moderation.

Ask the LWS team and its community a question

GDPR: Controller: LWS-Ligne Web Services. Purpose: moderation and public publication of your question, possible notification of an answer. Legal basis: consent (Art. 6(1)(a) GDPR). Email retention: 90 days after notification, 12 months maximum without an answer. To exercise your rights, see the GDPR section of our Terms and Conditions.