moon-boot
v0.0.11
Published
> A Project followed by SpringBoot For Nodejs
Downloads
3
Readme
moon-boot
What
A Project followed by SpringBoot For Nodejs
Why
SpringBoot
is the most popularMicroservice
Framework.- By
IOC
, It's simply to organize your project structure.
How to use
const { start } = require('moon-boot')
start(__dirname)
// For Class Mode
const { start } = require('moon-boot')
class Main {
constructor() {
start(__dirname)
}
}
new Main()
We suggest the second way to use this. For
Decorator
is easy to use with less code, is right?
Create with npx
$ npx create-moon-boot myProject
Decorator
LifeCycleHooks
AfterScan
AfterEnv
AfterLog
BeforeStart
AfterStart
@Value
To load env as Param@Bean() class TestService { @Value('profiles.active') activeProfile!: string // Give a placeholder @Value('server.port:8080') activeProfile!: string // Transform Type @Value('someData:{"name":"anc"}', { type: User }) someData!: User }
@Autowired
To load Beans@Bean() class TestService { @Autowired() test2Service: Test2Service @Autowired('test2Service') otherName: Test2Service }
@Bean
To Register Bean!!! difference: When Bean have not be used, it will not load
@Bean('otherName') class TestService {}
@BeforeBean
To run before Bean register@BeforeBean((env) => { console.log(env) }) @Bean('otherName') class TestService {}
@Condition
To run before Bean register, will no be load when returnfalse
@Condition((env) => { return '8080' === env('server.port') }) @Bean('otherName') class TestService {}
@Schedule
Supportnode-schedule
timed task formoon-boot
@Bean() class TestService { @Schedule('0 * * * * *') test() { return 'run in cron' } }
Plugins
How to build plugins? See
@moon-boot/plugin-express
as example If you want register, you must providebean
to be scaned fromindex
Rest
=>@moonboot/plugin-express
// This Moudle will auto use when installed // See project For More Information // index.ts import { start } from 'moon-boot' class Main { constructor() { start(__dirname) } } new Main() // controller.ts @Controller() class TestController { @Get('test/:id') test(@Body(UserParam) userParam: UserParam) { return 'success' } }
Redis
=>@moonboot/plugin-redis
@Bean() class TestService { @Autowired() redisTemplate!: RedisTemplte test() { return this.redisTemplate.mget() } }
Mysql
=>@moonboot/plugin-mysql
@Bean() class TestService { @Autowired() mysqlTemplate!: MysqlTemplate test() { return this.mysqlTemplate.query() } }
Mysql
=>@moonboot/plugin-mysql-mybatis
// TestService @Bean() class TestService { @Autowired() testMapper!: TestMapper test() { return this.testMapper.query() } } // TestMapper class User { @Alias('user_name') userName: string } @Bean() class TestMapper { @Select('select 1 from dual') @Type([Array, User]) test(): Promise<User[]> { return this.testMapper.query() } }
FAQ
Q: Why use Decorator
A: Simple
Q: Why not nestjs
A: It works well, but in some case, It's too big.
LifeCycle
Scan
We will scan the directory you provide, and thenode_modules
align with packagemoon-boot
and startsWith@moon-boot/
- Hook
AfterScan
Env
We will scan the directory you provide, to findapplication.yma?l
- Hook
AfterEnv
Log
Loadlog4js
- Hook
AfterLog
- Hook
BeforeStart
- Hook
AfterStart