1.0.7 • Published 1 year ago
AcheronJS - an ExpressJS clone for learning purpose

Installation
npm i acheronjs
Quick start
const Acheron = require("acheronjs")
const app = new Acheron()
app.get("/", (req, res) => {
res.send("Hello World")
})
app.listen(3000, () => {
console.log("Listening on port 3000")
})
import AcheronJS from "acheronjs"
import { Request, Response } from "acheronjs/type"
const app = new Acheron()
app.get("/", (req: Request, res: Response) => {
res.send("Hello World")
})
app.listen(3000, () => {
console.log("Listening on port 3000")
})
API reference
Api | Usage |
---|
app.use(middleware) | Using middleware |
app.METHOD(path, ...handlers[]) | Method provides the routing functionality, currently has GET , POST , PUT , DELETE , PATCH |
app.routes | Show all routes |
app.register(routerFunction) | Register route, see example |
app.locals | Same as ExpressJS's app.locals |
app.use(app.static(prefix, rootDir)) | Use to serve static files |
app.formidable(options) | This package uses formidable to configure the response data, see more |
app.listen(port, listeningListener) | Start listening on port number |
Api | Usage |
---|
req.clientIp | Get client's IP |
req.body | Get request body data |
req.cookies | Get all request cookies |
req.query | Get all request query strings |
req.params | Get all request parameters |
Api | Usage |
---|
res.cookie(name, value, options?) | Set cookie to response |
res.send(body, config?) | Send data to response, default is statusCode: 200 , contentType: text/plain |
res.json(object, config?) | Send data to response as JSON format, default is statusCode: 200 |
res.internalError(body) | Send 500 to response with a custom message |
res.render(filePath, object, config?) | Send file as response, it uses Handlebars as a default engine |
res.notFound() | Send 404 not found to response |
res.set(headers) | Set multiple headers to response |
res.append(name, value) | Append value to name header |
res.attachment(filename?) | Same as ExpressJS's res.attachment() |
res.get(name) | Get header's value |
res.sendFile(path, options, callback) | Same as ExpressJS's res.sendFile() |
res.download(pathDir, filename, options, callback) | Same as ExpressJS's res.download() |
res.fileTransfer(file, options, callback) | Same as ExpressJS's res.sendfile() |
res.clearCookies(name, options) | Clear response's cookies |
Build the project
git clone https://github.com/thawsgnotwjbu3103/AcheronJS.git
npm install
- Run npm run build command
npm run build
License
MIT