How to Install

yarn add @rafat97/express-made-easy

or 

npm i @rafat97/express-made-easy

Basic Application

const { ExpressApplication } = require("@rafat97/express-made-easy");

const expressApp = new ExpressApplication()
  .addDefaultMiddleware()
  .getMethod("/", (req, res) => {
    res.send("Hello World!");
  })
  .startServerSync();

More Complex Example

/**
* Application Middleware
*/
const dataM = (req: any, res: any, next: any) => {
  console.log("dataM");
  next();
};

/**
* Application Router
*/
const routerAPI = new ExpressApplicationRouter()
  .addMiddleware((req, res, next) => {
    console.log("Middleware A");
    next();
  })
  .getMethod("/", dataM, dataM, dataM, (req, res, next) => {
    // throw new Error("Error message");
    res.send("Hello World! routerAPI");
  });

/**
*  Application Options
*/
const config: IOptions = {
  appName: "Example Application",
  appHost: "127.0.0.1",
  appPort: 3000,
  appSecret: "TestSecret1234",
  logDir: `${__dirname}/extra/logs/`,
  viewDir: `${__dirname}/views/`,
  viewEngine: ViewEngine.HBS,
  staticContentDir: `${__dirname}/public/`,
  fabIconPath: `${__dirname}/public/images/favicon.png`,
  helmet: {
    contentSecurityPolicy: false,
  },
  rateLimiter: {
    // windowMs: 15 * 60 * 1000, // 15 minutes
    windowMs: 1 * 60 * 1000, // 15 minutes
    max: 60, // Limit each IP to 100 requests per `window` (here, per 15 minutes)
    standardHeaders: false, // Return rate limit info in the `RateLimit-*` headers
    legacyHeaders: false, // Disable the `X-RateLimit-*` headers
    message: JSON.stringify({ message: "Too Many Request" }),
  },
  session: {
    secret: "TestSecret1234",
    resave: false,
    saveUninitialized: true,
    cookie: {},
  },
  csrf: { cookie: true },
};

/**
*  Application Create
*/
const expressApp = new ExpressApplication(config)
  .addMultipleMiddleware(mid1, mid2, mid1)
  .addCookieParser()
  .addResponseTime()
  .addServerFavicon()
  .addMethodOverwriteHeader()
  .addFileUpload()
  .addRateLimiter()
  .addView()
  .addStaticContent()
  .addJSONParser()
  .addCompression()
  .addHelmet()
  .addCsrf()
  .addCors()
  .getMethod("/", demoGet)
  .router("/api", routerAPI)
  .addErrorHandler(demoErrorHandler)
  .addMiddleware(demoRouterNotFound)
  .startServerSync();

ExpressApplication All The Methods

Method name Purpose
addMultipleMiddleware You can add multiple middleware
addCookieParser Parse the cookie. It used cookie-parser package
addResponseTime Show the response time on header.
addServerFavicon Setting favicon.ico on server.
getMethod URL route http GET method
postMethod URL route http POST method
patchMethod URL route http patch method
putMethod URL route http put method
deleteMethod URL route http delete method
allMethod URL router accept all types of method

ExpressApplicationRouter All The Methods