Skip to content

ProfessorSolo/Node2Know-BasicHTTPServer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node2Know — Basic HTTP Server

A minimal Node.js web server using the core http module.

This repo is your first taste of “server-side JavaScript” without any frameworks:

  • create a server
  • respond to requests
  • view the result in your browser

✅ Prereqs

  • Node.js installed (includes node)

Verify:

node -v

📄 What's in this repo?

  • server.js — a basic HTTP server that responds with plain text

▶️ Run the server

From the project folder:

node server.js

You should see:

Server running at http://127.0.0.1:3000/

🌐 View it in a browser

Open:

  • http://127.0.0.1:3000/

You should see:

Hello Node Server!

👀 Run with watch mode

Node can restart the server automatically when server.js changes:

node --watch server.js

Now change the response string in res.end(...), save, and refresh your browser.

Stop the server with:

  • Ctrl + C

🧠 What the code demonstrates

Core module

  • const http = require("http");

Creating the server

  • http.createServer((req, res) => { ... })
    The callback runs every time a request hits the server.

Writing a response

  • res.statusCode = 200
  • res.setHeader("Content-Type", "text/plain")
  • res.end("Hello Node Server!")

Listening for requests

  • server.listen(port, hostname, () => { ... })

📁 Project Structure

.
├── server.js
└── README.md

License

Node2Know-Learn-1.0 (see LICENSE).

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors