j
jaipkg.dev
packages / app / jai-server

jai-server

2afd679app

Fast, simple, secure, powerful web Framework for node. REST API server

MIT ยท updated 2 years ago

Jai Server: Ultra-Fast

Jai-Server logo Fast, Powerfull, Robust web framework for creating API in Node.js


Twitter Follow Linkedin: Harpal Singh GitHub followers npm version


About

Jai Server is an ultra-high-performance, easy-to-use web framework for Node.js, engineered for building lightning-fast and highly scalable web applications and APIs.

With its innovative lightweight architecture and powerful features, Jai Server dramatically outperforms popular frameworks like Express.js while maintaining simplicity, flexibility, and developer-friendly ergonomics.

๐Ÿš€ Quick Start

npm install jai-server
const JaiServer = require('jai-server');

const app = JaiServer();

app.get('/', (req, res) => {
  res.send('Hello, Jai Server!');
});

app.listen({ port: 3000 }, () => {
  console.log('Jai Server is running on http://localhost:3000');
});

๐ŸŒŸ Features

  • โœ… Ready to use: Minimal setup required for rapid development #easy-setup
  • ๐Ÿ”„ RESTful API support: Create robust APIs with ease #rest-api
  • โš™๏ธ Flexible configuration: Easily adapt to your project needs #customizable
  • ๐Ÿ“ Static file serving: Effortlessly serve static content #static-files
  • ๐Ÿ›ฃ๏ธ Advanced routing: Powerful and intuitive routing system #routing
  • ๐Ÿ”€ Middleware support: Fine-grained control over request/response flow #middleware
  • ๐ŸŒ Comprehensive HTTP method support: GET, POST, PUT, PATCH, OPTIONS, HEAD, DELETE #http-methods
  • ๐Ÿ”’ Built-in security features: Enhance your application's security out of the box #security
  • ๐Ÿš€ Exceptional performance: Blazing fast, outperforming other popular frameworks #high-performance
  • โšก Low overhead: Minimal impact on system resources for efficient scaling #efficient
  • ๐Ÿ”ง HTTP/2 support: Leverage modern web technologies for improved speed #http2
  • ๐Ÿ”Œ Extensible plugin ecosystem: Extend functionality with a growing library of plugins #extensible

๐Ÿ“Š Performance Benchmark

Jai Server significantly outperforms Express.js in rigorous benchmark tests:

Jai Server Performance

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Stat    โ”‚ 2.5%  โ”‚ 50%   โ”‚ 97.5% โ”‚ 99%   โ”‚ Avg      โ”‚ Stdev   โ”‚ Max   โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Latency โ”‚ 14 ms โ”‚ 16 ms โ”‚ 34 ms โ”‚ 35 ms โ”‚ 20.68 ms โ”‚ 7.48 ms โ”‚ 54 ms โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Stat      โ”‚ 1%      โ”‚ 2.5%    โ”‚ 50%     โ”‚ 97.5%   โ”‚ Avg      โ”‚ Stdev  โ”‚ Min     โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Req/Sec   โ”‚ 46,367  โ”‚ 46,367  โ”‚ 46,847  โ”‚ 48,191  โ”‚ 47,126.4 โ”‚ 675.32 โ”‚ 46,361  โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Bytes/Sec โ”‚ 9.18 MB โ”‚ 9.18 MB โ”‚ 9.27 MB โ”‚ 9.54 MB โ”‚ 9.33 MB  โ”‚ 134 kB โ”‚ 9.18 MB โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

237k requests in 5.03s, 46.7 MB read

Express.js Performance

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Stat    โ”‚ 2.5%  โ”‚ 50%   โ”‚ 97.5%  โ”‚ 99%    โ”‚ Avg      โ”‚ Stdev    โ”‚ Max    โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Latency โ”‚ 68 ms โ”‚ 71 ms โ”‚ 116 ms โ”‚ 126 ms โ”‚ 74.66 ms โ”‚ 11.31 ms โ”‚ 154 ms โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Stat      โ”‚ 1%      โ”‚ 2.5%    โ”‚ 50%     โ”‚ 97.5%   โ”‚ Avg      โ”‚ Stdev    โ”‚ Min     โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Req/Sec   โ”‚ 10,775  โ”‚ 10,775  โ”‚ 13,855  โ”‚ 13,991  โ”‚ 13,221.6 โ”‚ 1,231.34 โ”‚ 10,773  โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Bytes/Sec โ”‚ 2.65 MB โ”‚ 2.65 MB โ”‚ 3.41 MB โ”‚ 3.44 MB โ”‚ 3.25 MB  โ”‚ 303 kB   โ”‚ 2.65 MB โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

67k requests in 5.02s, 16.3 MB read

Key Performance Insights

  • 3x Faster: Jai Server handles an impressive ~40,304 req/sec compared to Express.js's ~13,221 req/sec
  • 67% Lower Latency: 24.32ms average for Jai Server vs 74.66ms for Express.js
  • 2.6x Higher Throughput: 8.5 MB/sec for Jai Server vs 3.25 MB/sec for Express.js
  • Consistent Performance: Jai Server shows remarkably low standard deviation in requests per second, indicating stable and reliable performance under high load
  • Efficient Resource Utilization: Jai Server processes 3 times more requests while maintaining lower and more consistent latency

Jai Server delivers exceptional, consistent, and scalable performance, making it the ideal choice for high-load applications, microservices, real-time systems, and performance-critical projects. #performance-comparison #high-throughput #low-latency

๐Ÿ“š Table of Contents

๐Ÿ“ฅ Installation

Get started with Jai Server in your project:

npm install jai-server

๐ŸŽฏ Usage Examples

Basic Server

const JaiServer = require('jai-server');

const app = JaiServer();

app.get('/', (req, res) => {
  res.send('Welcome to Jai Server!');
});

app.listen({ port: 3000 }, () => {
  console.log('Server running on http://localhost:3000');
});

Serve Static Files

const JaiServer = require('jai-server');

const app = JaiServer({
  static: {
    dir: `${__dirname}/public`,
    basePath: '/static',
  },
});

app.listen({ port: 3000 }, () => {
  console.log('Static files served at http://localhost:3000/static');
});

HTTPS and HTTP/2 Support

const fs = require('fs');
const JaiServer = require('jai-server');

const app = JaiServer({
  http2: true,
  allowHTTP1: true,
  https: {
    key: fs.readFileSync('path/to/key.pem'),
    cert: fs.readFileSync('path/to/cert.pem'),
  },
});

app.get('/', (req, res) => {
  res.send('Secure Jai Server!');
});

app.listen({ port: 443 }, () => {
  console.log('Secure server running on https://localhost');
});

RESTful API with Route Parameters

const JaiServer = require('jai-server');

const app = JaiServer();

app.get('/users/:id', (req, res) => {
  res.json({ userId: req.params.id, message: 'User details' });
});

app.listen({ port: 3000 });

Using Middleware and Routers

const JaiServer = require('jai-server');

const app = JaiServer();
const router = JaiServer.Router();

// Middleware
app.use((req, res, next) => {
  console.log(`Request received at ${new Date()}`);
  next();
});

// Router
router.get('/hello', (req, res) => {
  res.send('Hello from the router!');
});

app.use('/api', router);

app.listen({ port: 3000 });

Built-in Response Methods

res.send(data)

Sends a response in HTML, text, or any other format. Automatically sets the appropriate Content-Type header.

app.get('/hello', (req, res) => {
  res.send('Hello, World!');
});

res.json(data)

Sends a JSON response with Content-Type: application/json.

app.get('/user', (req, res) => {
  res.json({ id: 1, name: 'John Doe' });
});

res.redirect(link, [statusCode])

Redirects the client to the given URL. The default status code is 302.

app.get('/old-route', (req, res) => {
  res.redirect('/new-route');
});

res.status(statusCode)

Sets the HTTP status code for the response. Chainable with other response methods.

app.get('/error', (req, res) => {
  res.status(404).send('Page Not Found');
});

res.header(key, value)

Sets custom headers for the response.

app.get('/custom-header', (req, res) => {
  res.header('X-Custom-Header', 'MyValue').send('Header set!');
});

res.sendFile(filePath, [options], [callback])

Serves a file to the client. Options can include root directory, cache settings, etc.

app.get('/download', (req, res) => {
  res.sendFile('path/to/file.txt',{
    fallthrough:false // Optional: default false
  },(err)=>{ // Optional Call Back/Next

  });
});

Middleware and Routers

Jai Server supports middleware and routers for more complex applications:

const JaiServer = require('jai-server');
const app = JaiServer();
const router = JaiServer.Router();

// Middleware
app.use((req, res, next) => {
  console.log('Time:', Date.now());
  next();
});

// Router
router.get('/hello', (req, res) => {
  res.send('Hello from the router!');
});

app.use('/api', router);

app.listen({ port: 3000 });

๐Ÿ“˜ API Reference

JaiServer(options)

Creates a new Jai Server instance.

Options

Option Type Description Default
host string Host name 'localhost'
port number Port number 3000
static object Static file serving options (jai-static) null
https object HTTPS options null
http2 boolean Enable HTTP/2 false
allowHTTP1 boolean Allow HTTP/1 on HTTP/2 server true
allowHTTP1 boolean Allow HTTP/1 on HTTP/2 server true
timeout number Timeout req after ms, default 60000(1min) 60000

app.METHOD(path, handler)

Routes an HTTP request, where METHOD is the HTTP method in lowercase.

app.get('/path', (req, res) => { /* ... */ });
app.post('/path', (req, res) => { /* ... */ });
// Other HTTP methods: put, patch, delete, options, head

app.use([path,] function [, function...])

Mounts middleware function(s) at the specified path.

app.listen(options[, callback])

Starts the server.

๐Ÿš€ Advanced Features

  • Middleware Chaining: Create complex request processing pipelines
  • Custom Error Handling: Implement application-specific error management
  • Request Body Parsing: Built-in support for JSON and URL-encoded bodies
  • Modular Routing: Organize routes using the Router class
  • WebSocket Support: Real-time, bidirectional communication
  • Database Integration: Easy connection with popular databases
  • Authentication Middleware: Secure your routes and APIs
  • Rate Limiting: Protect your server from abuse
  • CORS Support: Configure Cross-Origin Resource Sharing
  • Compression: Optimize response size for faster transmission

๐Ÿ“„ License

Jai Server is open-source software licensed under the MIT license.


Author

Harpal Singh: @hsk11 . Website: Jaijs.org.

Built with โค๏ธ by Harpal Singh

#jai-server #node-js-framework #web-development #backend #api-development #performance-optimization #microservices #realtime-applications #node-js #web-framework #high-performance #rest-api #http2 #express-alternative #api #web-api #restapi #http-server #nodejs-api Enhanced Response Methods #jaijs