Gathering detailed insights and metrics for @ibrahimanshor/my-express
Gathering detailed insights and metrics for @ibrahimanshor/my-express
Gathering detailed insights and metrics for @ibrahimanshor/my-express
Gathering detailed insights and metrics for @ibrahimanshor/my-express
npm install @ibrahimanshor/my-express
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
4
1const { createApp } = require('@ibrahimanshor/my-express');
2
3const app = createApp({
4 port: 4000, // default 4000
5 env: 'development', // default 'development'
6 staticPath: '', // default current directory
7 staticDir: 'public', // default 'public'
8});
9
10app.run();
1const { createApp } = require('@ibrahimanshor/my-express'); 2 3const myMiddleware = (app) => { 4 app.use((req, res, next) => { 5 console.log('running middleware'); 6 7 next(); 8 }); 9}; 10 11const app = createApp({ 12 setupMiddleware: myMiddleware, 13}); 14 15app.run();
1const { createApp } = require('@ibrahimanshor/my-express'); 2 3const myRouter = (app) => { 4 app.get('/', (req, res) => res.send('hello world')); 5}; 6 7const app = createApp({ 8 setupRoute: myRouter, 9}); 10 11app.run();
1const { createApp } = require('@ibrahimanshor/my-express'); 2 3// default en or from header accept language 4const messages = { 5 en: { 6 greet: 'hello world', 7 }, 8 id: { 9 greet: 'halo dunia', 10 }, 11}; 12 13// usage: req.polyglot.t(key) 14const myRouter = (app) => { 15 app.get('/', (req, res) => res.send(req.polyglot.t('greet'))); 16}; 17 18const app = createApp({ 19 messages, 20 locale: 'en', // default en 21});
1const { Container } = require('@ibrahimanshor/my-express'); 2 3// Register 4Container.register('greet', 'Hello'); 5 6// Factory 7Container.register('myFunction', () => { 8 console.log('my factory function'); 9}); 10 11// Factory With Depedency 12Container.register('myGreetFunction', ({ greet }) => { 13 console.log(greet); 14}); 15 16// Get 17console.log(Container.get('greet')); // Hello 18console.log(Container.get('greet')); // Hello 19console.log(Container.get('myFunction')); // my factory function 20console.log(Container.get('myGreetFunction')); // Hello
1const { createApp } = require('@ibrahimanshor/my-express'); 2 3const { 4 helpers: { createRequestValidator }, 5} = require('@ibrahimanshor/my-express'); 6const { body } = require('express-validator'); 7 8const postRequest = [body('name').exists().isString().notEmpty()]; 9const myRouter = (app) => { 10 app.post('/', createRequestValidator(postRequest), (req, res) => 11 res.json(req.body) 12 ); 13}; 14 15const app = createApp({ 16 messages, 17});
1// Import Exceptions 2const { 3 exceptions: { 4 HttpException, 5 UnprocessableEntityException, 6 ConflictException, 7 NotFoundException, 8 UnauthorizedException, 9 ForbiddenException, 10 }, 11} = require('@ibrahimanshor/my-express'); 12 13// Usage 14const { createApp } = require('@ibrahimanshor/my-express'); 15 16const myRouter = (app) => { 17 app.get('/', (req, res, next) => { 18 try { 19 throw new NotFoundException(); 20 } catch (err) { 21 next(err); 22 } 23 }); 24}; 25 26const app = createApp(); 27 28app.run(); 29 30// GET / return 404
1// Import Responses 2const { 3 responses: { SuccessReponse, CreatedResponse }, 4} = require('@ibrahimanshor/my-express'); 5 6// Usage 7const { createApp } = require('@ibrahimanshor/my-express'); 8 9const myRouter = (app) => { 10 app.get('/', (req, res) => { 11 return new SuccessReponse().send(req, res); 12 }); 13}; 14 15const app = createApp(); 16 17app.run(); 18 19// GET / return 200
1const { 2 utils: { 3 check: { isConflict, isForbidden, isNotFound, isUndefined }, 4 }, 5} = require('@ibrahimanshor/my-express'); 6 7const hasProblem = true; 8 9isConflict(hasProblem); // throw ConflictException if argument is true 10isForbidden(hasProblem); // throw ForbiddenException if argument is true 11isNotFound(hasProblem); // throw NotFoundException if argument is true 12isNotFound(hasProblem); // throw NotFoundException if argument is true 13isUndefined(user); // return true if argument undefined
1const { 2 utils: { 3 converter: { stringToBoolean }, 4 }, 5} = require('@ibrahimanshor/my-express'); 6 7stringToBoolean('true'); // true 8stringToBoolean('false'); // false 9stringToBoolean('error'); // false
1const { 2 utils: { 3 database: { paginate }, 4 }, 5} = require('@ibrahimanshor/my-express'); 6 7paginate({ page: 1, limit: 10 }); // { offset: 0, limit: 10 } 8paginate({ page: 2, limit: 10 }); // { offset: 10, limit: 10 } 9paginate({ page: 3, limit: 30 }); // { offset: 60, limit: 30 }
1const { 2 utils: { 3 query: { extractQueryOrder, extractQueryPage }, 4 }, 5} = require('@ibrahimanshor/my-express'); 6 7const getPostsRoute = (req, res, next) => { 8 const order = extractQueryOrder(req.query); 9 10 return res.json(order); // { order: { column: req.query.sort, direction: req.query.order } } 11}; 12const getUserssRoute = (req, res, next) => { 13 const page = extractQueryPage(req.query); 14 15 return res.json(page); // { page: { page: req.query.page, limit: req.query.limit } } 16};
1const { 2 utils: { 3 validator: { confirmed, related }, 4 }, 5} = require('@ibrahimanshor/my-express'); 6const { body } = require('express-validator'); 7 8const postRequest = [ 9 body('password') 10 .exists() 11 .isString() 12 .notEmpty() 13 .confirmed('password_validation'), 14 body('password_validation').exists().isString().notEmpty(), 15 body('email').exists().isString().notEmpty().related('name'), 16 body('name').exists().isString().notEmpty(), 17];
No vulnerabilities found.
No security vulnerabilities found.