Deploy a Node.js app from Git on Stack2
Start with a small HTTP server you can test locally, then use Git deployment and a web worker on Stack2. Before deploying, confirm the Node.js runtime and how incoming web requests are routed to your worker.
Make one small app and test it locally
Save this as server.mjs at the repository root. The example needs no packages and reads its listening port from the PORT environment variable. Port 3000 is its local fallback.
import { createServer } from 'node:http';
const port = Number(process.env.PORT ?? '3000');
createServer((request, response) => {
if (request.url === '/health') {
response.writeHead(200, { 'Content-Type': 'application/json' });
response.end(JSON.stringify({ status: 'ok' }));
return;
}
response.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });
response.end('Hello from Node.js');
}).listen(port, '0.0.0.0');
Run node server.mjs from the repository root and open http://localhost:3000/health. Look for {"status":"ok"}. Commit the file and push it to the Git repo you’ll deploy. See the Node.js HTTP documentation for how the server works.
Deploy from Git and configure the web worker
- Confirm the hosting settings. Check that your Node.js hosting setup supports the runtime you need. Confirm the port the platform routes to and how that port reaches the process.
- Deploy the branch. Use Git deployment to deploy the repository and branch with
server.mjs. For a private repository, arrange authorised access using your approved deployment method. - Set the startup command. Set the web worker’s working directory to the deployed repository root and its command to
node server.mjs. If your setup supplies a port throughPORT, the example reads it. If your setup uses a different variable or port setting, match the app to that configuration before starting it. - Start the worker and verify it. Open
/healthon your configured site URL. Expect HTTP 200 and the same JSON response as the local test. If you’re using your own domain, follow the domain and HTTPS checklist.
The sample was tested locally. Confirm your Stack2 deployment settings before using it on your hosting account.
If the site fails to respond
You manage releases and worker restarts. Stack2 provides platform support by ticket, and white glove setup is available as a separate service.