Skip to content

This repository demonstrates a simple web server written natively in Node.js.

Notifications You must be signed in to change notification settings

FarrelAD/Basic-Web-Server-NodeJS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Basic Node.js Web Service Project

NodeJS

This is a basic web service project built with native Node.js, without any external frameworks. It covers basic routing, handling different HTTP methods, and working with URL parameters and query strings. The goal of this project is to serve as a reference for anyone looking to understand how a web service can be written using just Node.js.

Features

  • Basic Routing: Set up routes for different endpoints.
  • Route with Parameters: Handle dynamic routes with URL parameters.
  • Query Parameters: Extract and process query strings from the URL.
  • HTTP Methods: Support for common HTTP method: GET, POST, PUT, DELETE

Getting Started

Prerequisites

Ensure you have Node.js installed on your machine.

Installation

  1. Clone the repository:
    git clone https://github.com/FarrelAD/Basic-Web-Service-NodeJS.git
  2. Navigate into the project directory:
    cd Basic-Web-Service-NodeJS
  3. Install any required dependencies (if applicable):
    npm install

Running the Server

To start the web service, run the following command:

npm run start

The server will be running at http://localhost:5000

Endpoints

Here are the key endpoints that you can interact with:

GET / : Returns a simple welcome message and provide simple form to handle request input
GET /users : Fetch all users
GET /users/:id : Fetch a data by their ID
POST /users : Add a new user
PUT /users/:id : Update user information
DELETE /users/:id : Delete a user by their ID
GET /search?name=&job= : Retrieves data based on user input from a search form, filtering results by name and job

Query Parameters

Example: /search?name=John&job=data+analyst Query parameters can be extracted and used in request processing.

HTTP Methods

The service supports the following HTTP methods:

GET: Retrieve data.
POST: Submit new data.
PUT: Update existing data.
DELETE: Remove data.

Code Structure

The project is simple and has the following structure:

/root
├─ index.js       # Main server logic
└── /src
       ├─ /controller # A handler for any request
       ├─ /data           # JavaScript object format to store dummy data
       └─ /routes         # Contains routing logic for different endpoints

License

This project is licensed under the MIT License.

Acknowledgments

This project is intended to help others learn the basics of building a web service with Node.js.

About

This repository demonstrates a simple web server written natively in Node.js.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published