Node.js lets you run JavaScript outside the browser. We'll create a tiny HTTP server, use npm to manage dependencies, and deploy the app to a free hosting provider.
Install Node
Download Node LTS from nodejs.org or use nvm (nvm install --lts).
Minimal server
const http = require('http');
const port = process.env.PORT || 3000;
const server = http.createServer((req,res) => {
res.setHeader('Content-Type','text/plain');
res.end('Hello from Node');
});
server.listen(port, ()=> console.log('Listening on', port));
npm and scripts
Initialize with npm init -y, then add a start script in package.json:
"scripts":{
"start":"node index.js"
}
Deploy
Services like Render, Railway, and Fly.io have free tiers for small apps. Connect your GitHub repo and let the platform build and run your server. Ensure you read environment variables and use process.env.PORT.