Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

async-app

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-app

An express wrapper for handling async middlewares, order middlewares, schema validator, and other stuff

  • 2.0.10
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
272
decreased by-22.73%
Maintainers
1
Weekly downloads
 
Created
Source

Async App

async-app is an express wrapper for handling async middlewares, schema validation, and other stuff.

Installation

npm i --save async-app

Usage ( Basic example)

import {
  badRequest,
  createApp,
  Opts,
  errorMiddleware,
} from 'async-app';

interface User {
  email: string;
  name: string;
  password: string;
}

interface Entities extends BaseEntities {
  user: User;
}

const options: Opts = {
};

const app = createApp<Entities>(options);

// No more try/catch, async-app does it for you
const getUserData = async (user: User) => {
  const profile = await fetchProfile(user.email);
	
  if (!profile) {
    throw badRequest('USER_NOT_FOUND');
  }
	
  return { // JSON that will be sent to the client
    ...profile,
    password: undefined
  }; 
};

app.get(                             // Method
  '/user',                           // Path
  'Returns user data',               // Summary (optional)
  `You must be authenticated!`,      // Description (optional)
  authenticated(),                   // Middlewares
  req => getUserData(req.user),      // Request handler
  200,                               // Success status code (optional)
);

app.use(errorMiddleware); // To translate exceptions into HTTP error responses

Keywords

FAQs

Package last updated on 04 Feb 2019

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