Welcome to rjweb-server š
Easy Way to create a web Server in node.js
Install
npm i rjweb-server
Usage
Initialize Server
const webserver = require('rjweb-server')
const routes = new webserver.RouteList()
routes.set(webserver.types.get, '/hello', async(ctr) => {
ctr.print(`Hello, ${ctr.query.get("name")}! How are you doing?`)
})
routes.set(webserver.types.get, '/hello/:name', async(ctr) => {
ctr.print(`Hello, ${ctr.param.get("name")}! How are you doing?`)
})
webserver.start({
bind: '0.0.0.0',
cors: false,
port: 5000,
urls: routes
}).then((res) => {
console.log(`webserver started on port ${res.port}`)
})
Custom 404 Page
webserver.start({
bind: '0.0.0.0',
cors: false,
port: port,
urls: routes,
notfound: async(ctr) {
ctr.status(404)
ctr.print(`page "${ctr.requestPath.pathname}" not found`)
}
}).then((res) => {
console.log(`webserver started on port ${res.port}`)
})
Author
š¤ 0x4096
š¤ Contributing
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Show your support
Give a āļø if this project helped you!
š License
Copyright Ā© 2022 0x4096.
This project is ISC licensed.