New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

express-string-controllers

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-string-controllers

Reduce imports with express wrapper

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

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

express-string-controllers

Reduce imports in your expressjs apps using a controllers wrapper

Installation

Using NPM

  npm install express-string-controllers --save

Using Yarn legacy

  yarn add express-string-controllers

Quick start

If your folder structure is something like this:

  • src
    • index.ts
    • controllers
      • PetsController.ts

index.ts

import express from 'express';
import App, { IExpress } from 'express-string-controllers';

// wrap your express app
const app: IExpress = new App(express());

app.get('/pets', 'PetsController.getPets');

// Replace with your port number
app.listen(4000, () => {
  console.log('app started');
});

PetsController.ts

class PetsController {
  static async getPets(req, res, next) {
    return res.status(200).json({
      pets: ['dog', 'cat']
    });
  }
};

export default PetsController;

You can also dictate your controllers folder path manually:


  • src
    • index.ts
    • custom
      • custom_controller
        • PetsController.ts

index.ts

import path from 'node:path';
import express from 'express';
import App, { IExpress } from 'express-string-controllers';

// wrap your express app
const controllersPath = path.resolve(__dirname, './custom/custom_controller');

const app: IExpress = new App(express(), controllersPath);

app.get('/pets', 'PetsController.getPets');

// Replace with your port number
app.listen(4000, () => {
  console.log('app started');
});

PetsController.ts

class PetsController {
  static async getPets(req, res, next) {
    return res.status(200).json({
      pets: ['dog', 'cat']
    });
  }
};

export default PetsController;

For more examples, check the __tests__ folder.

Using nodejs require

./index.js

const path = require('path');
const express = require('express');
const { App } = require("express-string-controllers");


// controller path
const cPath = path.join(__dirname, './controllers');

// init app
const app = new App(express(), cPath);

// define routes
app.get('/ban', 'PetsController.helloWorld');

app.listen(2000, () => {  console.log('server started');
});

./controllers/PetsController.js

// default exports
module.exports = class PetsController {
  static async helloWorld(req, res, next) {
    return res.send('hello world');
  }
}

Keywords

FAQs

Package last updated on 27 Feb 2022

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