A progressive Node.js framework for building efficient and scalable server-side applications.
Nest framework TypeScript base storage module.
$ npm install --save @peersyst/storage-module
- Import and register StorageModule in AppModule
import { Module } from "@nestjs/common";
import { StorageModule, StorageType } from "@peersyst/storage-module";
@Module({
imports: [
ConfigModule.forRoot(...),
StorageModule.register(ConfigModule, {
storageType: StorageType.LOCAL,
}),
...
],
...
})
export class AppModule {}
- Add StorageErrorCode and StorageErrorBody to app ErrorCodes
import { HttpStatus } from "@nestjs/common";
import { StorageErrorCode, StorageErrorBody } from "@peersyst/storage-module";
// Define app error codes
enum AppErrorCode {}
export const ErrorCode = { ...AppErrorCode, ...StorageErrorCode };
export type ErrorCodeType = AppErrorCode | StorageErrorCode;
export const ErrorBody: { [code in ErrorCodeType]: { statusCode: HttpStatus; message: string } } = {
// Define app error code bodies
...StorageErrorBody,
};
- Import StorageModule in the modules you want to use it
import { Module } from "@nestjs/common";
import { StorageModule, StorageType } from "@peersyst/storage-module";
@Module({
imports: [
StorageModule.register(ConfigModule, {
storageType: StorageType.LOCAL,
}),
...
],
...
})
export class ResourceModule {}
- Inject StorageService in the in the classes you want to use it
import { InjectRepository, Inject } from "@nestjs/common";
import { StorageServiceInterface } from "@peersyst/storage-module";
export class ResourceService {
constructor(
@InjectRepository(Resource) private readonly resourceRepository: Repository<Resource>,
@Inject("StorageService") private readonly storageService: StorageServiceInterface,
)
}
- Add configService configuration variables
export default (): any => ({
aws: {
region: process.env.AWS_REGION,
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
bucketName: process.env.AWS_BUCKET_NAME,
},
});
- Add configService configuration variables
export default (): any => ({
local: {
rootPath: process.env.LOCAL_ROOT_PATH,
},
});
Nest is MIT licensed.