How to host a Node.js Express API with public HTTPS
Taking an Express API from localhost:3000 to a production HTTPS endpoint comes down to three essentials: listening on 0.0.0.0, reading process.env.PORT, and exposing a fast /health endpoint.
Ce que vous allez apprendre :
- Estruturar uma API REST em Node.js 22 com Express e rotas CRUD.
- Configurar bind de rede em 0.0.0.0 e leitura dinâmica da variável PORT.
- Implementar rota de healthcheck (/health) e política de CORS segura.
- Proteger credenciais de banco de dados e segredos JWT em variáveis.
- Publicar a API na LoisaX via GitHub, pacote ZIP ou CLI.
- Vincular domínio personalizado com certificado HTTPS automático.
Download the ready Express API starter
Node.js 22 + Express with CORS, JSON parsing, /health, and sample REST routes.
Étape 01
Bind Express to 0.0.0.0 and process.env.PORT
Production edge routers forward HTTPS traffic to the port injected via PORT. Binding only to 127.0.0.1 blocks external routing — always pass "0.0.0.0" to app.listen.
1{2"name": "minha-api-express",3"version": "1.0.0",4"private": true,5"type": "module",6"main": "src/app.js",7"scripts": {8"start": "node src/app.js"9},10"engines": {11"node": ">=22"12},13"dependencies": {14"cors": "^2.8.5",15"express": "^4.21.2"16}17}
Étape 02
Expose a lightweight GET /health endpoint
Returning 200 OK from /health lets automated probes verify uptime in milliseconds.
Étape 03
Scope CORS to your frontend domain
Set cors({ origin: process.env.FRONTEND_URL }) in production so browser requests are restricted to your own web app.
Étape 04
Store DATABASE_URL and JWT secrets in variables
Add database strings and API keys in the console Variables view rather than committing .env files.
Étape 05
Deploy and verify over HTTPS
Push via GitHub or upload your .zip, then test curl https://your-app.../health and attach a custom CNAME domain whenever ready.
Étape 06
Une erreur ? Les plus fréquentes et leur solution
502 Bad Gateway right after boot
Cause : Server bound to localhost or ignored process.env.PORT.
Solution : Use app.listen(Number(process.env.PORT || 3000), "0.0.0.0").
Étape 07
Questions fréquentes
Yes. Every deployed API receives a public HTTPS URL ready for incoming webhooks.
Notre engagement envers les développeurs
Chez LoisaX, nous pensons que notre rôle va au-delà de l’hébergement et du cloud computing. Nous souhaitons également contribuer à l’apprentissage et à la progression de notre communauté.
Nous enrichissons continuellement notre catalogue de guides avec de nouveaux contenus sur les langages de programmation, l’intégration d’APIs, l’automatisation et le développement d’applications.
Autres guides pratiques
Tous les guides
Best Discord bot hosting in 2026

VPS or managed hosting for a bot?
