Create a Node.js server for app hosting
A Node.js deployment rarely fails because of the language: it fails because the main file cannot be found, a dependency is missing or the server listens on an unreachable address. Start from a minimal server with no dependencies, confirm it runs locally, then add your logic. You will then be able to tell a platform problem from a code problem.
Minimal structure
Two files are enough: the entry point and the manifest.
my-app/
index.js
package.jsonThe HTTP server
The code below uses only the standard library. It reads the port from the environment, listens on every interface and exposes a health route.
const http = require("node:http");
const port = Number(process.env.PORT) || 3000;
const server = http.createServer((req, res) => {
if (req.url === "/health") {
res.writeHead(200, { "content-type": "application/json" });
res.end(JSON.stringify({ status: "ok" }));
return;
}
res.writeHead(200, { "content-type": "text/plain; charset=utf-8" });
res.end("Hello from Node.js\n");
});
server.listen(port, "0.0.0.0", () => {
console.log(`listening on ${port}`);
});
process.on("SIGTERM", () => server.close(() => process.exit(0)));0.0.0.0 is essential: with 127.0.0.1 the server accepts only local connections and stays unreachable from outside. The 3000 fallback is for local development only; on the platform, PORT is provided.
The package.json
{
"name": "my-app",
"version": "1.0.0",
"private": true,
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"engines": {
"node": ">=20"
}
}main and the start script must point to the real file. If you rename index.js to server.js, update all three: the file name, main and the start command.
Deploy
- Upload the files or clone the repository into the service.
- Run
npm installif apackage.jsondeclares dependencies. - Confirm the start command is
node index.js(ornpm start). - Start, then read the console: the
listening on ...line must appear. - Call
/healthfrom outside to confirm the port is exposed.
Do not upload node_modules: the platform installs declared dependencies. However, always commit package-lock.json for reproducible installs.
Common errors
| Message | Cause | Fix |
|---|---|---|
Cannot find module |
missing dependency or wrong path | npm install, check main |
EADDRINUSE |
two processes on the same port | one process, use the assigned port |
| Site unreachable | listening on 127.0.0.1 |
listen on 0.0.0.0 |
PORT undefined |
variable read incorrectly | read process.env.PORT |
| Restart loop | exception at startup | read the console, fix the error |
A minimal server that answers on /health is the best diagnostic base: as long as it works, the problem is in your code, not the platform.
Advertisement
Was this article helpful?
Read next
- Understanding application hostingWhat the Pterodactyl platform handles for you, what you must provide, and the limits to know before deploying.
- Configure Node.js environment variablesRead, validate and define variables in the panel, without ever putting a secret in the Git repository.
- Understanding package.json and npmThe useful manifest fields, the difference between dependencies and dev tools, and when to use npm install or npm ci.