https://github.com/neerajkumar161/node-js-framework
A lightweight, minimal Node.js framework similar to Express
https://github.com/neerajkumar161/node-js-framework
framework library nodejs open-source pnpm typescript
Last synced: about 13 hours ago
JSON representation
A lightweight, minimal Node.js framework similar to Express
- Host: GitHub
- URL: https://github.com/neerajkumar161/node-js-framework
- Owner: neerajkumar161
- Created: 2023-06-04T11:16:17.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-06-06T09:00:56.000Z (almost 3 years ago)
- Last Synced: 2025-03-11T07:46:33.181Z (about 1 year ago)
- Topics: framework, library, nodejs, open-source, pnpm, typescript
- Language: TypeScript
- Homepage:
- Size: 12.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Nodejs-Framework
This is a lightweight, minimal and custom [Express](https://github.com/expressjs/express)-like library implemented in TypeScript, without any additional libraries, providing basic functionality for building web applications.
## Features
- Middleware support for handling HTTP requests
- Routing based on URL and HTTP method
- Error handling middleware
- Built-in server using the Node.js `http` module
## Installation
To use the library in your project, you can install it via npm. Run the following command:
```shell
npm install nodejs-framework // NOT uploaded yet
```
## Usage
Import the library and create an instance of the App class:
```ts
import App from './';
const app = new App();
app.listen(3400, () => {
console.log('Server is listening on port 3400!')
})
```
## Middleware
You can register middleware functions to be executed for every request using the app.use method:
```ts
app.use('/health', (req, res) => {
console.log(req.url)
res.end('Server is working fine!!!')
})
```
## Route Handlers
Define route handlers using the app.get and app.post methods:
```ts
app.get('/getRoute', (req, res) => {
console.log('Im in getRoute', req.body)
res.end('Im in getRoute')
})
app.post('/postRoute', (req, res) => {
console.log('PostRoute', req.body)
res.end('PostRoute')
})
```
## API Reference
###
```ts
app.use(route: string, handler: RequestHandler): void
```
Registers middleware to be executed for all requests or for a specific route.
- `route` (required): The route URL for the middleware. If not provided, it will be registered for all routes.
- `handler`: The middleware function.
###
```ts
app.get(route: string, handler: RequestHandler): void
```
Registers a route handler for HTTP GET requests.
- `route`: The route URL pattern.
- `handler`: The route handler function.
###
```ts
app.post(route: string, handler: RequestHandler): void
```
Registers a route handler for HTTP POST requests.
- `route`: The route URL pattern.
- `handler`: The route handler function.
###
```ts
app.listen(port: number, callback?: () => void): void
```
Starts the server and listens for incoming requests on the specified port.
- `port`: The port number to listen on.
- `callback` (optional): A function to be called when the server starts listening.
## License
This project is licensed under the MIT License. See the LICENSE file for details.
## Author
[Neeraj Kumar](https://www.github.com/neerajkumar161)