1.4.5 • Published 6 months ago

jai-server v1.4.5

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

Jai Server

Fast, simple, secure, powerful web Framework for node.


Twitter Follow Linkedin: Harpal Singh

GitHub followers

Features

  • Ready to use
  • Create REST APIs
  • Easy to configure
  • Server Static Files
  • Create Multiple Routes
  • Control API flow
  • Supported Http Methods : GET, POST, PUT, PATCH, OPTIONS, HEAD, DELETE

Installation

Install my-project with npm

  npm install jai-server

Usage / Examples

Hello World

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

const app = JaiServer(/* options */);

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

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

Serve Static Files

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

const App = JaiServer(
  {
    static: {
      dir: `${__dirname}/public`, // public folder,
      basePath: '/static', // Optional
    },

  },
);

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

Jai Server Http2 / Https

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

const app = JaiServer({
    http2: true,
    allowHTTP1: true, // allow Http1.0 request
    https: // enables Https
      {
        key: fs.readFileSync('_location_for_key_'),
        cert: fs.readFileSync('_location_for_cert_'),
      }
  
  });

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

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

Capture Params

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

const app = JaiServer({
    http2: true,
    allowHTTP1: true, // allow Http1.0 request
    https: // enables Https
      {
        key: fs.readFileSync('_location_for_key_'),
        cert: fs.readFileSync('_location_for_cert_'),
      }
  
  });
// url http://localhost:3000/Jai-Server
app.get('/:firstName-:lastName', (req, res) => {
  console.log(req.params)
  res.send(`Hello ${req.params.firstName} ${req.params.lastName}`);
});

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

Routes

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

const app = JaiServer();
const router = JaiServer.Router();
// http://localhost:3000/hello
router.get('/hello', (req, res) => {
  res.send('Hello World!');
});
app.use(router);
// OR
app.use('/route-prefix', router);


// http://localhost:3000
app.get('/', (req, res) => {
  res.send('Home Page!');
});

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

API Reference

Options

ParameterTypeDescription
hoststringhost name. default: localhost
portnumberport to use, default: 3000
staticobjectto serve static files {dir: "./public_path", basePath: '/public'}, default: null
httpsobjectto create secure server {key,cert}, default: 3000
http2booleanto create http2 server, default: false
allowHTTP1booleanto serve http1 request on http2 server, default: true

Author: @hsk11

1.4.5

6 months ago

1.4.4

6 months ago

1.4.3

8 months ago

1.13.1

12 months ago

1.13.0

12 months ago

1.13.3

12 months ago

1.11.9

1 year ago

1.4.2

12 months ago

1.4.1

12 months ago

1.1.1

2 years ago

1.1.9

2 years ago

1.0.11

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.3

2 years ago

1.0.1

2 years ago