中文版 (Chinese) | English
This is a sample application demonstrating how to use nest-simple-config with NestJS. The project showcases configuration management, TypeORM integration, and RESTful API development.
- Configuration Management: Uses
nest-simple-config
for handling application settings from JSON files and environment variables
This sample demonstrates:
- JSON Configuration: Loading settings from
appsettings.json
- Environment Variables: Overriding configuration with environment variables
- Type Safety & Validation: Defining option classes with class-validator for configuration validation
- TypeScript Interfaces: Converting configuration.get() any type to strongly typed interfaces
- Dependency Injection: Injecting configuration into services and controllers
- Node.js (version 16 or higher)
- npm or yarn package manager
# Install dependencies
$ npm install
The application uses appsettings.json
for configuration. You can override settings using environment variables with the NestApp
prefix.
Example environment variables:
export NestApp__app__port=3001
export NestApp__database__database=./custom.sqlite
export NestApp__server__host=0.0.0.0
# Development mode
$ npm run start
# Watch mode (recommended for development)
$ npm run start:dev
# Debug mode
$ npm run start:debug
# Production mode
$ npm run start:prod
The application will start on http://localhost:3000
by default.
Once the application is running, you can access the following endpoints:
GET /
- Application informationGET /users
- Get all usersPOST /users
- Create a new userGET /users/:id
- Get user by IDPUT /users/:id
- Update userDELETE /users/:id
- Delete userGET /server
- Get server configurationGET /server/status
- Get server status
# Unit tests
$ npm run test
# Test in watch mode
$ npm run test:watch
# End-to-end tests
$ npm run test:e2e
# Test coverage
$ npm run test:cov
This project is MIT licensed.