Node.js First Example: Console and Web Apps
Node.js applications come in two main flavors: console-based and web-based. This guide walks through one of each ÔÇö the simplest possible Hello World, plus a basic HTTP server.
Node.js Tutorial:-
Complete Python Course:-
Console-Based Hello World
// console_example1.js
console.log('Hello UpdateGadh');
// Run with:
// node console_example1.js
Web-Based HTTP Server
A simple Node.js web server requires just three steps: import the http module, create the server, listen on a port.
// main.js
const http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, { 'Content-Type': 'text/plain' });
response.end('Hello World
');
}).listen(8081);
console.log('Server running at ');
Run and Test
node main.js
# Open browser at:
#
# Output: Hello World
Modern Alternative
For production apps, use the Express framework ÔÇö it builds on http with routing, middleware, and much cleaner syntax:
const express = require('express');
const app = express();
app.get('/', (req, res) => res.send('Hello World'));
app.listen(8081);
Download New Real Time Projects:- Click here
Complete Advance AI topics:-
Conclusion
You wrote your first Node.js console app and HTTP server. Next step ÔÇö try Express for real apps. For more tutorials, stay tuned to .
how to run node js in terminal
sample node-js application
node js download
node js run command
node js hello world example
node js first example for beginners
node js first example w3schools
express js node js tutorial