New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

webu.js

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webu.js

A lightweight and flexible web server framework for Node.js.

  • 1.1.3
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Webu.js

Webu.js Logo

GitHub license GitHub issues GitHub stars

A web server framework for Node.js.

Installation

npm install webu.js

Usage

const fs = require('fs');
const path = require('path');
const Webu = require('webu.js');

const webu = new Webu();

// Handling GET requests
webu.get('/', (req, res) => {
  res.send(200, '<h1>Hello, World!</h1>', { 'Content-Type': 'text/html' });
});

// Handling PUT requests
webu.put('/update', (req, res) => {
  res.send(200, 'Resource updated successfully!');
});

// Handling files
webu.get('/file', (req, res) => {
    // Specify the path to your HTML file
    const htmlFilePath = path.join(__dirname, 'index.html');

    // Read the HTML file
    fs.readFile(htmlFilePath, 'utf8', (err, data) => {
        res.writeHead(200, { 'Content-Type': 'text/html' });
        res.end(data);
    });
});

// Setting a custom error page for 404 errors
webu.error((req, res) => {
  res.send(404, '<h1>Custom 404 Error Page</h1>', { 'Content-Type': 'text/html' });
});

// Starting the server on port 3000
webu.start(3000, (port) => {
    console.log(`Server listening on: ${port}`);
});

Features

  • Simple and lightweight web server framework.
  • Support for handling different HTTP methods, including GET and PUT.
  • Easily set custom error pages for specific status codes.
  • Customize the start message for the server.

Documentation

Handling HTTP Methods

Webu.js allows you to handle various HTTP methods such as GET, PUT, POST, DELETE, PATCH, HEAD, OPTIONS, and TRACE.

webu.get('/', (req, res) => {
  // Handle GET request for '/'
});

webu.put('/update', (req, res) => {
  // Handle PUT request for '/update'
});

// Similarly, you can use post, delete, patch, head, options, and trace methods

Custom Error Pages

Set custom error pages to handle specific HTTP status codes. In this example, a custom 404 error page is set.

webu.error((req, res) => {
  res.send(404, '<h1>Custom 404 Error Page</h1>', { 'Content-Type': 'text/html' });
});

Contributing

Feel free to contribute by opening issues or submitting pull requests. See CONTRIBUTING.md for more information.

License

This project is licensed under the ISC License - see the LICENSE file for details.

Technical Support by https://thintry.com/

Thintry Logo

Keywords

FAQs

Package last updated on 22 Dec 2023

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