Deploying JavaScript Applications on PythonLib: VPS, Docker and Cloud

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

How to stop being afraid and start deploying: your first production environment

\n\n

You've written a cool JavaScript application. It works locally, tests pass, and the console shows no errors. But as soon as the question "how do I run this on a real server?" comes up, many people start to panic. VPS, Docker, cloud platforms — it sounds like something from the world of DevOps, not frontend or Node.js backend.

\n\n

In reality, it's simpler than it seems. In this article, we'll break down three main approaches to deploying JavaScript applications: on VPS, in Docker, and in the cloud. I'll show real code examples, explain the pros and cons of each method, and you'll be able to choose what's right for your project.

\n\n

What is deployment and why is it even needed?

\n\n

Deployment is the process of deploying your application on a server where it will be available to users 24/7. Local development is only the first step. Without deployment, your project remains just a set of files on your computer.

\n\n

For JavaScript developers, three scenarios are particularly relevant:

\n\n
    \n
  • Deploying on VPS — full control over the server.
  • \n
  • Deploying in Docker — isolation and reproducibility of the environment.
  • \n
  • Deploying on cloud platforms — minimal hassle with infrastructure.
  • \n
\n\n

Let's look at each option in detail.

\n\n

Deploying on VPS: manual management and full control

\n\n

VPS (Virtual Private Server) is a virtual server where you can install any OS and configure everything manually. It's a classic that gives maximum flexibility.

\n\n

Step 1: Choosing and setting up the server

\n\n

First, rent a VPS (for example, from DigitalOcean, Hetzner, or Timeweb). The minimum configuration for Node.js is 1 vCPU and 1 GB RAM. Choose Ubuntu 22.04 LTS.

\n\n

After gaining SSH access, perform basic setup:

\n\n
ssh root@your_server_IP\n\n# Update packages\napt update && apt upgrade -y\n\n# Install Node.js 20.x\ncurl -fsSL https://deb.nodesource.com/setup_20.x | bash -\napt-get install -y nodejs\n\n# Check\nnode -v\nnpm -v
\n\n

Step 2: Cloning the repository and installing dependencies

\n\n

Let's assume your application is on GitHub. Clone it to the server:

\n\n
git clone https://github.com/your_username/your_repository.git\ncd your_repository\nnpm install --production
\n\n

Step 3: Setting up environment variables

\n\n

Never store secrets in code. Create a .env file:

\n\n
nano .env\n\n# Example content\nPORT=3000\nDATABASE_URL=mongodb://localhost:27017/myapp\nJWT_SECRET=your_super_secret_key
\n\n

Step 4: Running via PM2

\n\n

PM2 is a process manager for Node.js. It automatically restarts the application if it crashes and keeps it running:

\n\n
npm install -g pm2\npm2 start app.js --name "my-app"\npm2 save\npm2 startup
\n\n

Done! Your application is running on port 3000. To make it accessible on port 80, use Nginx as a reverse proxy.

\n\n
apt install nginx -y\nnano /etc/nginx/sites-available/default
\n\n

Inside the file, add:

\n\n
server {\n    listen 80;\n    server_name your_domain.com;\n\n    location / {\n        proxy_pass http://localhost:3000;\n        proxy_http_version 1.1;\n        proxy_set_header Upgrade $http_upgrade;\n        proxy_set_header Connection 'upgrade';\n        proxy_set_header Host $host;\n        proxy_cache_bypass $http_upgrade;\n    }\n}
\n\n

Restart Nginx:

\n\n
nginx -t\nsystemctl restart nginx
\n\n

Pros of VPS: full control, you can configure anything, low cost.

\n

Cons: you need to handle security, backups, and updates yourself.

\n\n

Deploying in Docker: containerization for reproducibility

\n\n

D

Blogs

Book Recommendations