Skip to content

convox-examples/nodejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node.js Example for Convox

A Node.js Express application ready to deploy on Convox.

This example demonstrates how to deploy a Node.js application with Express on Convox. The app includes health checks, environment variable usage, and RESTful API endpoints - showing best practices for Node.js services in production.

Deploy to Convox Cloud for a fully-managed platform experience, or to your own Convox Rack for complete control over your infrastructure. Either way, you'll get automatic SSL, load balancing, and zero-downtime deployments out of the box.

Deploy to Convox Cloud

  1. Create a Cloud Machine at console.convox.com

  2. Create the app:

convox cloud apps create nodejs -i your-machine-name
  1. Deploy the app:
convox cloud deploy -a nodejs -i your-machine-name
  1. View your app:
convox cloud services -a nodejs -i your-machine-name

Visit your URL to see the JSON response!

Deploy to Convox Rack

  1. Create the app:
convox apps create nodejs
  1. Deploy the app:
convox deploy -a nodejs
  1. View your app:
convox services -a nodejs

Visit your URL to see the JSON response!

Application Endpoints

  • GET / - Main endpoint with environment info
  • GET /health - Health check endpoint
  • GET /api/info - Application information
  • POST /api/echo - Echo back JSON data

Test the API

# Get main endpoint
curl https://your-app-url/

# Check health
curl https://your-app-url/health

# Get app info
curl https://your-app-url/api/info

# Test POST endpoint
curl -X POST https://your-app-url/api/echo \
  -H "Content-Type: application/json" \
  -d '{"message": "Hello Convox!"}'

Local Development

npm install
PORT=3000 npm start

Visit http://localhost:3000 to see your app running locally.

Scaling

Convox Cloud

convox cloud scale web --count 2 --cpu 500 --memory 1024 -a nodejs -i your-machine-name

Convox Rack

convox scale web --count 2 --cpu 500 --memory 1024 -a nodejs

Environment Variables

Set custom environment variables:

Convox Cloud

convox cloud env set API_KEY=secret NODE_ENV=production -a nodejs -i your-machine-name

Convox Rack

convox env set API_KEY=secret NODE_ENV=production -a nodejs

Project Structure

  • Node.js 20 with Express framework
  • Health check endpoints for monitoring
  • Environment-based configuration
  • Non-root container for security
  • Optimized Docker layer caching

Common Commands

View logs

Cloud:

convox cloud logs -a nodejs -i your-machine-name

Rack:

convox logs -a nodejs

Run one-off commands

Cloud:

convox cloud run web "node --version" -a nodejs -i your-machine-name

Rack:

convox run web "node --version" -a nodejs

Access shell

Cloud:

convox cloud exec web sh -a nodejs -i your-machine-name

Rack:

convox run exec web sh -a nodejs

About

Express

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •