k-ordered, conflict-free ids generator in a distributed environment for egg.js and midway.js
npm install egg-koid
![GitHub tag]()

![]()




``sh`
npm i egg-koid
Edit ${app_root}/src/config/plugin.ts:
`ts`
export const koid = {
enable: true,
package: 'egg-koid',
}
`ts
/ location: ${app_root}/src/config/config.${env}.ts /
import { KoidEggConfig, genConfigRandom } from 'egg-koid'
export const koid: KoidEggConfig = {
client: {
debug: false,
koidConfig: genConfigRandom(), // value or void 0
},
}
// OR
export const koid: KoidEggConfig = {
client: {
debug: false,
koidConfig: {
dataCenter: 0,
worker: 1,
}
},
}
`
`ts
import { Plugin, Provide } from '@midwayjs/decorator'
import type { Koid } from 'egg-koid' // note: import type
@Provide()
export class UserService {
@Plugin() readonly koid: Koid
}
``