JSPM

  • Created
  • Published
  • Downloads 10
  • Score
    100M100P100Q57257F
  • License MIT

Fast , simple and powerful web framework. RESTFul API server

Package Exports

  • jai-server
  • jai-server/src/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (jai-server) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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

Parameter Type Description
host string host name. default: localhost
port number port to use, default: 3000
static object to serve static files {dir: "./public_path", basePath: '/public'}, default: null
https object to create secure server {key,cert}, default: 3000
http2 boolean to create http2 server, default: false
allowHTTP1 boolean to serve http1 request on http2 server, default: true

Author: @hsk11