
Research
/Security News
Contagious Interview Campaign Escalates With 67 Malicious npm Packages and New Malware Loader
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.
express-string-controllers
Advanced tools
Reduce imports in your expressjs apps using a controllers wrapper
npm install express-string-controllers --save
yarn add express-string-controllers
If your folder structure is something like this:
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:
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.
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');
}
}
FAQs
Reduce imports with express wrapper
We found that express-string-controllers demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.