Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More ā†’
Socket
Sign inDemoInstall
Socket

rjweb-server

Package Overview
Dependencies
Maintainers
1
Versions
375
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rjweb-server

Easy Way to create a Web Server in Node.js

  • 0.2.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Welcome to rjweb-server šŸ‘‹

Version Documentation Maintenance

Easy Way to create a web Server in node.js

šŸ  Homepage

Install

npm i rjweb-server

Usage

Initialize Server

/* ************ *
 * EXPERIMENTAL *
 * ************ */
// You shouldnt use the current
// State for Production Use

const webserver = require('rjweb-server')
const routes = new webserver.RouteList()

// ctr.query.get... is ?name=
routes.set(webserver.types.get, '/hello', async(ctr) => {
  ctr.print(`Hello, ${ctr.query.get("name")}! How are you doing?`)
})

// ctr.param.get... is :name, example /hello/0x4096
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 / 500 Page

/* ************ *
 * EXPERIMENTAL *
 * ************ */
// You shouldnt use the current
// State for Production Use

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`)
  }, reqError: async(ctr) => {
    ctr.status(500)
    ctr.print(`ERROR!!! ${ctr.error}`)
  }
}).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.

FAQs

Package last updated on 02 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with āš”ļø by Socket Inc