Skip to content

This is a sample application demonstrating how to use [nest-simple-config](https://github.com/cymondez/nest-simple-config) with NestJS. The project showcases configuration management, TypeORM integration, and RESTful API development.

License

Notifications You must be signed in to change notification settings

cymondez/nest-simple-config-sample

Repository files navigation

NestJS Simple Config Sample

中文版 (Chinese) | English

Nest Logo

Description

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.

Features

  • Configuration Management: Uses nest-simple-config for handling application settings from JSON files and environment variables

Key Configuration Features

This sample demonstrates:

  1. JSON Configuration: Loading settings from appsettings.json
  2. Environment Variables: Overriding configuration with environment variables
  3. Type Safety & Validation: Defining option classes with class-validator for configuration validation
  4. TypeScript Interfaces: Converting configuration.get() any type to strongly typed interfaces
  5. Dependency Injection: Injecting configuration into services and controllers

Prerequisites

  • Node.js (version 16 or higher)
  • npm or yarn package manager

Installation

# Install dependencies
$ npm install

Configuration

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

Running the Application

# 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.

API Endpoints

Once the application is running, you can access the following endpoints:

  • GET / - Application information
  • GET /users - Get all users
  • POST /users - Create a new user
  • GET /users/:id - Get user by ID
  • PUT /users/:id - Update user
  • DELETE /users/:id - Delete user
  • GET /server - Get server configuration
  • GET /server/status - Get server status

Testing

# 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

Learn More

License

This project is MIT licensed.

About

This is a sample application demonstrating how to use [nest-simple-config](https://github.com/cymondez/nest-simple-config) with NestJS. The project showcases configuration management, TypeORM integration, and RESTful API development.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published