https://github.com/criszst/myexpress
π | Minimal Express built with TypeScript
https://github.com/criszst/myexpress
express express-ts express-typescript jest jest-tests ts typescript
Last synced: over 1 year ago
JSON representation
π | Minimal Express built with TypeScript
- Host: GitHub
- URL: https://github.com/criszst/myexpress
- Owner: criszst
- Created: 2025-01-28T03:19:45.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-01T23:21:55.000Z (over 1 year ago)
- Last Synced: 2025-03-02T00:23:27.437Z (over 1 year ago)
- Topics: express, express-ts, express-typescript, jest, jest-tests, ts, typescript
- Language: TypeScript
- Homepage:
- Size: 4.56 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# π MyExpress
A lightweight Express-like framework that I built for fun. While I wonβt be implementing all the features of Express, Iβll be adding the essential ones to keep the project clean and functional.
## Checklist
- [x] Basic app with `send`, `post`, `res`, `req`, and `next` methods.
- [x] Recreated some libraries to reduce dependencies (better for security).
- [x] Interfaces to keep the code clean and maintainable.
- [ ] Function to send an HTML file to the client.
- [ ] More built-in middlewares.
- [ ] Additional tests.
## Features
- **`send(data)`** β Sends an object or text directly to the client.
- **`json(data)`** β Returns a JSON response.
- **`download(filePath)`** β Sends a file to be downloaded by the client.
- **`redirect(url)`** β Redirects the client to a specific URL (public domain or local project file).
- **`sendFile(filePath)`** *(in development...)* β Sends the content of a file to the client (currently supports only `.txt` files).
## Usage
Some quick examples of how to use it:
```ts
response.send("Hello, client!"); // Sends a text response
response.json({ hello: "world" }); // Sends a JSON response
response.download("./download.test.txt"); // Forces a file download
response.redirect("https://example.com"); // Redirects the user
response.sendFile("./index.html"); // Sends the content of a file
```
**Note:** The `sendFile` method is still under development and currently only supports `.txt` files
## Installation
First, clone the repository:
```sh
git clone https://github.com/criszst/MyExpress.git
```
Navigate into the project directory:
```sh
cd MyExpress
```
Then, install dependencies:
```sh
npm install
```
If you want to run tests (optional but recommended):
```sh
npm run test
```
Since Node.js can't run TypeScript files directly, compile the project:
```sh
npm run build
```
Finally, start the server:
```sh
npm run start
```
## Running the Server
The server runs on port `3000`. Once it's up, visit:
[http://localhost:3000](http://localhost:3000)
You should see the message:
`Hello, world!`