1.0.7 • Published 1 year ago

acheronjs v1.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

AcheronJS - an ExpressJS clone for learning purpose

npm version install size

Installation

npm i acheronjs

Quick start

  • Javascript
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")
})
  • Typescript
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

  • App:
ApiUsage
app.use(middleware)Using middleware
app.METHOD(path, ...handlers[])Method provides the routing functionality, currently has GET, POST, PUT, DELETE, PATCH
app.routesShow all routes
app.register(routerFunction)Register route, see example
app.localsSame 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
  • Request:
ApiUsage
req.clientIpGet client's IP
req.bodyGet request body data
req.cookiesGet all request cookies
req.queryGet all request query strings
req.paramsGet all request parameters
  • Response:
ApiUsage
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

  • Clone project
git clone https://github.com/thawsgnotwjbu3103/AcheronJS.git
  • Run npm install command
npm install
  • Run npm run build command
npm run build

License

MIT

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago