This project is a simple HTTP server built with Node.js using only core modules, without any external libraries except for Nodemon (installed for development convenience). The server responds to specific routes with custom messages and demonstrates fundamental server creation and route handling in Node.js.
- Root Route ("/"): Returns a welcome message when accessed via a GET request.
- Add Route ("/add"): Returns a message indicating the add page for a GET request.
- Admin Route ("/admin"): Returns a message indicating the admin page for a GET request.
Ensure that you have Node.js installed on your machine.
- Clone the repository:
git clone (https://github.com/ajmalfaris11/node-server-basics.git)
- Navigate to the project directory:
cd <project-directory>
- Initialize the project with npm and install Nodemon:
npm init -y npm install nodemon --save-dev
To start the server with Nodemon for auto-restarts:
npx nodemon <your-main-server-file>.js
Alternatively, you can start the server with:
node <your-main-server-file>.js
The server will be accessible at http://localhost:3200
.
Route | Method | Description |
---|---|---|
/ |
GET | Returns a welcome message |
/add |
GET | Returns the add page message |
/admin |
GET | Returns the admin page message |
This project showcases the following:
- Basic HTTP server creation using Node.js.
- Handling specific routes and responding with custom messages.
- Nodemon setup for development ease, allowing for automatic restarts upon file changes.