Security News
Highlights from the 2024 Rails Community Survey
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
arrow-express
Advanced tools
Aim of this library is to make express applications bootstrapping easy and fast with zero configuration.
Main principles:
To install package use command:
npm install arrow-express
import Express from 'express';
import BodyParser from "body-parser";
import Compression from 'compression';
import cors from 'cors';
import {Application, Controller, Route} from 'arrow-express';
const ExpressApp = Express();
ExpressApp.use(BodyParser());
ExpressApp.use(Compression());
ExpressApp.use(cors());
Application({
port: 8080,
app: ExpressApp
}).registerController(
Controller()
.prefix('users')
.registerRoutes(
Route()
.method('get')
.handler(
(req) => getUser(req.body.id)
),
Route()
.method('post')
.path('create')
.handler(
(req) => createUser(req.body.id)
)
),
).start();
/**
* Created paths in express application:
* GET:/users
* POST:/users/create
*
* For full example application check out example folder.
*/
Point of start for every application. Here you can configure Express application or port used by your application.
registerController
- register controller in application.start
- starts application, register controllers routes in express app and connect to configured portApplication({
port: 8080,
app: Express(),
})
.start();
Controller is used to manage group of routes.
/**
* We advise to split each controller into separate file.
* Exaple folder structure can be found in example folder.
*/
function LoginController () {
return Controller()
.prefix('login');
}
function UserController () {
return Controller()
.prefix('user');
}
Application({port: 8080})
.registerController(
LoginController(),
UserController(),
)
.start();
prefix
- register controller prefix which will be used by all routesregisterRoute
- register route in controllerRoute is used to manage route handling.
/**
* Similar to controllers we advise to split every guard / route into separate file.
*/
function CheckToken (): UserId {
// here we check if user is logged by proper token
return userId;
}
function getUserRoute() {
return Route()
.method('get')
.path('myself')
.contextGuard(CheckToken)
.handler(async (req: Express.Request, res: Express.Response, userId: UserId) => {
// here we can get user using UserId received from guard
return user;
});
}
function LoginController () {
return Controller()
.prefix('user')
.registerRoutes(
getUserRoute()
);
}
Application({port: 8080})
.registerController(
LoginController(),
)
.start();
// Registered path will be: '/user/myself'
method
- register method used for routepath
- register path of route alongside with prefix it is used to create full pathhandler
- set request handler, here you can handle requestcontextGuard
- used to add pre-checks or side operations for request if guard throw error, handler is not calledRoute handler receive 3 arguments:
request
- which is Express.Request for pathresponse
- which is Express.Responsecontext
- which is optional context returned by last guardFeatures of route handler:
res
then library won't try to send result pf handler.Route Guard receive 2 arguments:
request
- which is Express.Request for pathresponse
- which is Express.ResponseRoute Guard can return context which can be used in handler later. If route guard throw error route handler won't be called.
FAQs
Library to bootstrap express applications with zero configuration
The npm package arrow-express receives a total of 444 weekly downloads. As such, arrow-express popularity was classified as not popular.
We found that arrow-express demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Security News
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.