Student Activity
Student Activity (30-min)
Activity: Building and Testing a Basic HTTP Server
Step-by-Step Procedure:
Step 1: Set Up a Basic HTTP Server:
Create a file named
basicServer.jsand write the following code:const http = require('http'); const server = http.createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ message: 'Hello, World!' })); }); server.listen(3000, () => { console.log('Server running at http://localhost:3000'); });
Step 2: Run the Server:
Open a terminal, navigate to the file location, and run:
// bash node basicServer.js
Step 3: Test the Server with Postman:
Open Postman.
Send a GET request to
http://localhost:3000.Inspect the response body (JSON format) and headers.
Step 4: Test with a Browser:
Open a browser and visit
http://localhost:3000.Observe the output as JSON in the browser window.
Last updated