springify.ts
v0.0.22-SNAPSHOT
Published
A framework like JAVA Spring mean for every Java Programmer that need low resource tools for an Restful Service.
Downloads
7
Readme
Springify.ts@perdiatmaja
Introduction
This is a node js framework that based on Fastify. Simplify the use of fastify using decorator, it similar with JAVA Spring boot.
Installation:
To install any pre requirements please use below command:
npm install
npm i -g typescript@latest
npm i -g ts-node
TS Configuration:
Please use below TS configuration:
{
"compilerOptions": {
"target": "es2019",
"module": "commonjs",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"resolveJsonModule": true
}
}
Env Configuration:
To start the app yo must define the env, for local please name it .env.local, or prod .env.prod, or if you can use .env for all environment. These are the list of propreties you can register:
COOKIE_NAME=""
IP_BIND=""
PORT=""
ROUTER_PATH="/routers/"
How to Use:
Start the application
import "reflect-metadata"
import dotenv from 'dotenv'
import { container } from "tsyringe"
import { SpringifyApp } from "springify.ts"
const env = `.env${process.argv.length > 2 ? ".".concat(process.argv[2]) : ""}`
dotenv.config({ path: `${process.env.PWD}/${env}` })
const app: SpringifyApp = container.resolve(SpringifyApp)
app.start()
Create new Router:
import { GET, POST, PathMapping, SpringifyRouter } from "springify.ts";
import { injectable } from "tsyringe";
@injectable()
@PathMapping("/v1/test")
class TestRouter extends SpringifyRouter {
@GET("/")
public async test(): Promise<any> {
return "Test"
}
@POST("/")
public async testPost(): Promise<any> {
return "Test"
}
}
export default TestRouter