A base API built with NestJS, TypeORM, PostgreSQL, and Google authentication. Includes structured logging with nestjs-pino.
- Node.js >= 18
- PostgreSQL (or a compatible connection URL)
- Yarn or npm
-
Clone the repository:
git clone <REPO_URL> cd base-api
-
Install dependencies:
npm install # or yarn install
-
Configure environment variables:
- Copy the example file and edit it:
cp .env.example .env
- Fill in the required values in
.env
(DB_URL, JWT_SECRET, GOOGLE_CLIENT_ID, etc).
- Copy the example file and edit it:
- Generate a migration:
npm run typeorm:migration:generate -- MIGRATION_NAME=YourMigrationName
- Run migrations:
npm run typeorm:migration:run
- Development mode:
npm run start:dev
- Production mode:
npm run build npm run start:prod
The API will be available on the port defined by NEST_PORT
(default: 3000).
The app uses nestjs-pino for structured logs. You can inject the logger in your controllers or services using:
import { Logger } from 'nestjs-pino';
constructor(private readonly logger: Logger) {}
this.logger.info('Log message');
Or use the custom logger AppLogger
:
import { AppLogger } from './app-logger/app-logger';
constructor(private readonly logger: AppLogger) {}
this.logger.success('Context', 'Success message');
The endpoint /auth/google/login
allows authentication with Google.
Send the Google token in the body:
{
"token": "GOOGLE_ID_TOKEN"
}
CORS is enabled for the frontend defined in the WEB_HOST
variable.
- Run tests:
npm run test
src/modules/
— Main app modulessrc/config/
— Environment configurationsrc/database/migrations/
— TypeORM migrations
MIT