- π₯ NestJS - A progressive Node.js framework
- β‘οΈ GraphQL with Apollo Server - Code-first approach
- π¦ MongoDB integration with Mongoose
- π§© Modular architecture
- π ESLint + Prettier for consistent code style
- π¦ Class Validator for DTO validation
- π Conventional Commits for structured commit messages
- Node.js (v14 or newer)
- MongoDB (local or Atlas connection)
- Yarn or NPM
- Clone the repository
git clone https://github.com/Ridho894/nestjs-graphql-mongo-starter.git
cd nestjs-graphql-mongo-starter
- Install dependencies
npm install
# or
yarn install
- Environment Setup
Create a .env
file in the root directory with the following variables:
# Server
PORT=3000
# MongoDB
MONGO_URI=mongodb://localhost:27017/nestjs-gql-mongo
# JWT
JWT_SECRET=your_jwt_secret_key
JWT_EXPIRES=1d
- Start the development server
npm run start:dev
# or
yarn start:dev
Your GraphQL API will be available at http://localhost:3000/graphql
Once your application is running, you can access the GraphQL Playground to interact with your API:
Screenshot: GraphQL Playground interface showing query execution
Here's a simple query you can try in the playground:
{
users {
_id
name
email
}
}
Command | Description |
---|---|
npm run build |
Builds the application |
npm start |
Starts the application |
npm run start:dev |
Starts the application in watch mode |
npm run start:debug |
Starts with debugging |
npm run start:prod |
Starts in production mode |
npm run lint |
Lints the code |
npm run test |
Runs tests |
npm run test:watch |
Runs tests in watch mode |
npm run test:cov |
Shows test coverage |
nestjs-gql-mongo-starter/
βββ src/
β βββ config/ # Configuration files and constants
β βββ graphql/ # GraphQL specific files
β βββ modules/ # Feature modules
β β βββ users/ # User module example
β β βββ dto/ # Data Transfer Objects
β β βββ schemas/ # Mongoose schemas
β β βββ users.module.ts
β β βββ users.resolver.ts
β β βββ users.service.ts
β βββ app.module.ts # Main application module
β βββ main.ts # Application entry point
βββ public/
β βββ screenshots/ # Screenshots for documentation
βββ test/ # Testing utilities
βββ .env # Environment variables (create this)
βββ .gitignore # Git ignore file
βββ nest-cli.json # NestJS CLI configuration
βββ package.json # Dependencies and scripts
βββ tsconfig.json # TypeScript configuration
βββ README.md # Documentation
- GraphQL API
- Code-first approach using decorators
- Schema auto-generation
- Resolvers for queries and mutations
This project follows Conventional Commits for clear and structured commit messages. This helps in maintaining a standardized commit history and automated versioning.
Each commit message consists of a header, an optional body, and an optional footer:
<type>(<scope>): <short summary>
β β β
β β βββ«Έ Summary in present tense. Not capitalized. No period at the end.
β β
β βββ«Έ Commit Scope (optional): modules|config|schema
β
βββ«Έ Commit Type: feat|fix|docs|style|refactor|test|chore|ci|build|perf
- feat: A new feature
- fix: A bug fix
- docs: Documentation only changes
- style: Changes that do not affect the meaning of the code (white-space, formatting, etc)
- refactor: A code change that neither fixes a bug nor adds a feature
- test: Adding missing tests or correcting existing tests
- chore: Changes to the build process or auxiliary tools
- ci: Changes to CI configuration files and scripts
- build: Changes that affect the build system or external dependencies
- perf: Performance improvements
feat(auth): add JWT authentication
fix(users): resolve issue with user creation
docs(readme): update installation instructions
Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'feat: add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request