Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
@axmit/express-core
Advanced tools
This package provide reusable module for creating express applications using TypeScript and NodeJS
Before using this package you need to authorize yourself into npm registry using npm adduser
npm i @axmit/express-core
or yarn add @axmit/express-core
This library includes modules to help you build your applications faster you only need to specify .env
to configure
your environment. Available .env variables:
PORT = 3030 //defines your server port
BASE_URL = /
Class ExpressApplicaion
is base express application class which contains almost all you need to create your awesome app
Usage example:
import { ExpressApplication } from '@axmit/express-core';
class YourApplicationName extends ExpressApplication {
async start() {
await super.start(yourConfigFile, pathToLogs);
}
}
new YourApplicationName().start();
After calling start
method your express server will start on specified by yourself port or on port 3030
by default
Also ExpressApplication
provides build in Dependency Injector(DI)
To add custom module define it like this
export function yourModuleName(dependency1, dependency2) {
//do something cooll here}yourModuleName.$inject = ['dependency1', 'dependency1'];
And register it in your application class
this.registerService('yourModuleName', yourModuleName);
Note: this
is an instance of the ExpressApplication
class
Now you can inject it in other modules using
moduleName.$inject = ['yourModuleName'];
Also you can provide optional dependencies using
moduleName.$inject = ['?yourModuleName'];
You can get registered service in ExpressApplication
class using
this.container.get('yourModuleName');
ExpressApplication
methodsParams:
ApplicationRouter
sectionThis method add new router to your application
Register service in DI container
Params
Add module to your application see Module
section
Add base definitions for swagger (ex. Errors, BaseEntities etc.)
Start application
Params:
Config variables:
withoutServer?: boolean; //if true will not start express server
validateRequests?: boolean; //if true will validate every request using json swagger schema
swaggerInfo?: ISwaggerInfo; //Swagger UI information
Schedules cron job to be fulfilled
Params:
Usage:
function getDateJob() {
console.log(new Date());
}
this.addJob('* * * * * *', () => getDateJob);
This will print current time every second
Stops application destroying database connections and stopping jobs and modules
Base http promise wrapped service to make http request
Usage:
import { httpClient } from '@axmit/express-core';
await httpClient.request(options | url);
See request
npm module for more info
Builder for express routing implementation, it provides extended version of express router by adding methods to write swagger docs (see example)
Using:
import { ApplicationRouterBuilder } from '@axmit/express-core';
const builder = new ApplicationRouterBuilder();
builder
.useNamespace('/yourPath')
.addSwaggerSchema({
swagerSchemaName: {
type: 'object',
required: ['id', 'name'],
properties: {
id: {
type: 'number',
description: 'id of something'
},
name: {
type: 'string',
description: 'name of somethiing'
}
}
}
})
.useSwaggerDocs({
get: {
tags: ['Your Tags'],
summary: 'Summary',
description: 'Descrition',
consumes: ['application/json'],
produces: ['application/json'],
parameters: [
{
name: 'filter',
description: 'filter',
required: false,
type: 'string',
in: 'query'
}
],
responses: {
'200': {
description: 'description',
type: 'array',
items: {
$ref: '#/definitions/swagerSchemaName'
}
}
}
}
})
.buildNamespace()
.get(yourMiddlewaresGoesHere);
export const awesomeRouter = builder.buildRouter();
By using useSwaggerDocs
and addSwaggerSchema
methods you can define your swagger docs which will be automatically compile and be available at http://yourHost:port/swagger
domain
To add this router into your application just call
this.addRouter('/', awesomeRouter);
in your base Application class
Define route namespace (ex. /users
, /users/:id
)
Adds swagger docs to namespace
Adds swagger definitions to router
Builds namespace and return express router route instance, where you can add any request methods
builder
.useNamespace('/test')
.buildNamespace()
.get((req, res, next) => {
res.json({
sampleString: 'string'
});
});
This code will create GET /test
endpoint which will return {"sampleString": "string"}
json object
Builds router to be implemented using ExpressApplication
addRouter
method
FAQs
A reusable module implementing express application
The npm package @axmit/express-core receives a total of 1 weekly downloads. As such, @axmit/express-core popularity was classified as not popular.
We found that @axmit/express-core demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers 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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.