Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thenewtoncode/server-using-node.js
A simple HTTP server built using Node.js. The server serves an HTML homepage, handles dynamic URLs for user-specific pages, provides an API endpoint, and returns appropriate responses for bad requests.
https://github.com/thenewtoncode/server-using-node.js
api backend dynamic html-css-javascript http http-server node-js nodejs nodejs-api nodejs-server server web
Last synced: about 1 month ago
JSON representation
A simple HTTP server built using Node.js. The server serves an HTML homepage, handles dynamic URLs for user-specific pages, provides an API endpoint, and returns appropriate responses for bad requests.
- Host: GitHub
- URL: https://github.com/thenewtoncode/server-using-node.js
- Owner: theNewtonCode
- Created: 2024-07-27T18:57:07.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-07-27T22:34:42.000Z (5 months ago)
- Last Synced: 2024-07-28T22:39:11.981Z (5 months ago)
- Topics: api, backend, dynamic, html-css-javascript, http, http-server, node-js, nodejs, nodejs-api, nodejs-server, server, web
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Server using Node.js
This project is a simple HTTP server built using Node.js. The server serves an HTML homepage, handles dynamic URLs for user-specific pages, provides an API endpoint, and returns appropriate responses for bad requests.
## Table of Contents
- [Features](#features)
- [Installation](#installation)
- [Usage](#usage)
- [File Structure](#file-structure)
- [License](#license)## Features
- Serves a static HTML homepage.
- Handles dynamic URLs to serve personalized user pages.
- Provides an API endpoint to serve JSON data.
- Returns 404 for unknown routes.## Installation
1. Clone the repository:
```sh
git clone https://github.com/theNewtonCode/Server-using-Node.js.git
cd simple-http-server
```2. Install the required dependencies:
```sh
npm install
```3. Create the necessary directories and files if they do not exist:
```sh
mkdir -p Frontend/static Backend
touch Backend/users.txt Frontend/static/index.html Frontend/static/api_data/text.txt
```4. Populate `Backend/users.txt` with usernames (one per line):
```txt
user1
user2
```5. Add content to `Frontend/static/index.html`:
```html
Homepage
Welcome to the Homepage
```6. Add some text content to `Frontend/static/api_data/text.txt`.
## Usage
1. Start the server:
```sh
node server.js
```2. Open your browser and navigate to `http://127.0.0.1:3000`.
3. To access a user-specific page, navigate to `http://127.0.0.1:3000/users/username`, where `username` is a name listed in `Backend/users.txt`.
4. To access the API endpoint, navigate to `http://127.0.0.1:3000/api/data`.
## File Structure
- `Backend/`
- `users.txt`: File containing usernames.
- `Frontend/`
- `static/`
- `index.html`: HTML file for the homepage.
- `api_data/`
- `text.txt`: File containing text data for the API endpoint.
- `server.js`: Main server file.## License
This project is licensed under the MIT License.