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.
- Basic app with
send
,post
,res
,req
, andnext
methods. - Recreated some libraries to reduce dependencies (better for security).
- Interfaces to keep the code clean and maintainable.
- Function to send an HTML file to the client.
- More built-in middlewares.
- Additional tests.
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).
Some quick examples of how to use it:
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"); // (Coming soon!) Sends the content of a file
Note: The sendFile
method is still under development and currently only supports .txt
files
First, clone the repository:
git clone https://github.com/criszst/MyExpress.git
Navigate into the project directory:
cd MyExpress
Then, install dependencies:
npm install
If you want to run tests (optional but recommended):
npm run test
Since Node.js can't run TypeScript files directly, compile the project:
npm run build
Finally, start the server:
npm run start
The server runs on port 3000
. Once it's up, visit:
You should see the message:
Hello, world!