New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

koa-context-loader

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-context-loader

load anything to koa context

latest
Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

koa-context-loader

NPM version build status code coverage license

load file module into app.context

Install

npm install koa-context-loader

yarn add koa-context-loader

Usage

// ./service/user.js

module.exports = {
  getUserId() {
    return 123;
  }
}

// ./app.js
const Koa = require('koa');
const app = new Koa();
const loader = require('koa-context-loader');
const path = require('path');

const options = {
  service: path.resolve(__dirname, './service'),
  alias: 'path'
}

loader(app.context, options)

app.use((ctx, next) => {
  // ctx[alias][filename][export_method]
  const id = ctx.service.user.getUserId(); // id:123
});

API

options {alias: keyof options, path: string}

options = {
  alias: path
}

path must be absolute

Keywords

koa

FAQs

Package last updated on 26 Dec 2017

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