This sample is the MongoDB + Firebase variant of the Node-Boot Express sample. It keeps the same core Express features as the plain sample—OpenAPI, Swagger UI, validation, scheduling, middleware hooks, authorization hooks, and typed HTTP clients—but swaps SQL persistence for MongoDB via TypeORM's MongoDB driver and enables Firebase Admin integration via @nodeboot/starter-firebase.
In this codebase, the Firebase-specific example is intentionally small: it wires the Firebase starter and injects Remote Config to list configuration versions. It does not currently verify Firebase Auth tokens, read/write Firestore, use Cloud Storage, or send FCM messages.
- Express app bootstrap with Node-Boot decorators in
src/app.ts - MongoDB persistence with
@nodeboot/starter-persistenceand TypeORM'smongodbdriver - Firebase Admin auto-configuration with
@nodeboot/starter-firebase - Authorization hooks with
@nodeboot/authorization - OpenAPI/Swagger support with
@nodeboot/starter-openapi - Request validation with
@nodeboot/starter-validation - Scheduled jobs with
@nodeboot/starter-scheduler - Typed outbound HTTP clients with
@nodeboot/starter-http - Actuator endpoints with
@nodeboot/starter-actuator
@EnableDI(Container)— uses TypeDI as the application container.@EnableOpenApi()— generates OpenAPI metadata from controllers/models.@EnableSwaggerUI()— enables Swagger UI for the generated spec.@EnableAuthorization(LoggedInUserResolver, DefaultAuthorizationResolver)— registers the sample current-user and authorization resolvers.@EnableActuator()— enables actuator-style operational endpoints.@EnableRepositories()— auto-configures TypeORM repositories and MongoDB access.@EnableScheduling()— enables@Scheduler(...)jobs.@EnableHttpClients()— enables declarative HTTP clients such asMicroserviceHttpClient.@EnableFirebase()— initializes the Firebase Admin starter and exposes Firebase beans for injection.@EnableValidations()— enables DTO/query validation.@EnableComponentScan()— scans and registers components/controllers/services/configurations.@NodeBootApplication()— marks the main Node-Boot application class.
- Node.js >= 18
- pnpm >= 7.5.1
- A MongoDB database (local MongoDB or MongoDB Atlas)
- A Firebase project plus a service account JSON file
- Install dependencies from the monorepo root:
pnpm install- Configure local overrides in
samples/sample-express-mongodb/app-config.local.yaml(or the includedapp-credentials.local.yamlif you prefer to keep secrets separate). Use placeholder values like this:
persistence:
mongodb:
database: "facts"
url: "mongodb+srv://<username>:<password>@<cluster>/<database>?retryWrites=true&w=majority"
integrations:
firebase:
serviceAccount: ./firebase.service-account.json
realtimeDatabaseUrl: https://<project-id>.europe-west1.firebasedatabase.app-
Place your Firebase service account JSON at the path referenced by
integrations.firebase.serviceAccount. -
Start the sample:
pnpm devsrc/server.ts is the bootstrap entrypoint. It instantiates FactsServiceApp and starts the Express server through NodeBoot.run(ExpressServer).
samples/sample-express-mongodb/
├── app-config.yaml
├── app-config.local.yaml
├── src/
│ ├── app.ts
│ ├── server.ts
│ ├── auth/
│ ├── clients/
│ ├── config/
│ ├── controllers/
│ ├── middlewares/
│ ├── models/
│ ├── persistence/
│ └── services/
└── package.json
Highlights:
src/controllers/— user, paging, and Firebase demo endpoints.src/services/— MongoDB-backed user logic, scheduler tasks, greeting hooks, and Firebase Remote Config access.src/persistence/— MongoDB entity, repositories, entity listeners, and demo data bootstrap.src/config/— app property binding, Express server config resolution, security middleware, and class-transform settings.src/auth/— sample authorization/current-user resolvers used by@EnableAuthorization(...).src/middlewares/— custom request logging and error handling.
The app config sets api.routePrefix: "/api", and each controller uses version "v1", so the routes below are exposed under /api/v1/....
GET /— returns all MongoDB users throughUserRepository.find().GET /external/— callshttps://jsonplaceholder.typicode.com/usersthroughMicroserviceHttpClient.GET /v2/— returns users by calling the injectedMongoClientdirectly.GET /v3/— returns users throughUserRepository.findAllUsingCollection().GET /v4/— returns users throughUserRepository.findAllUsingClient().GET /:id— declares a lookup route for a numeric:idparameter.POST /— creates a user fromCreateUserDto; protected with@Authorized().PUT /:id— updates a user password fromUpdateUserDto.DELETE /:id— deletes a user and returns{message: "User <id> successfully deleted"}.
GET /paginated— returnsUserPageusingPagingRequestquery parameters:page,pageSize,sortOrder,sortField.GET /cursor— returnsCursorUserPageusingCursorRequestquery parameters:pageSize,lastId,cursor,sortOrder,sortField.GET /paginated/filter— same as/paginated, but with a hard-coded filter ofemail = "example3@email.com".GET /cursor/filter— same as/cursor, but with the same hard-coded email filter.
POST /auth— logs a message and callsFirebaseService.callFirebase().
This endpoint does not verify a Firebase ID token, read Firestore, or return Firebase user data. It simply triggers a Remote Config API call and returns no body.
Firebase is enabled at application level with @EnableFirebase() in src/app.ts.
What the sample actually wires up:
src/services/firebase.service.tsinjectsFIREBASE_REMOTE_CONFIG_BEANasremoteConfig.RemoteConfig.FirebaseService.callFirebase()logsCalling Firebase, then callsfirebaseRemoteConfig.listVersions()and logs how many Remote Config versions were returned.src/controllers/firebase.controller.tsexposesPOST /api/v1/firebase/auth, which only delegates to that service method.
What it does not do:
- No Firebase Auth token verification
- No
verifyIdToken(...) - No Firestore collections/documents
- No Cloud Storage usage
- No Cloud Messaging / FCM usage
- No Realtime Database access in application code
The underlying starter can expose all of those services as injectable beans; see ../../starters/firebase/README.md. In this sample's checked-in config, integrations.firebase contains:
integrations:
firebase:
serviceAccount: ./firebase.service-account.json
realtimeDatabaseUrl: https://<your-project>.europe-west1.firebasedatabase.appThis sample uses @nodeboot/starter-persistence with:
persistence:
type: "mongodb"
cache: false
mongodb:
database: "facts"
url: "mongodb+srv://<username>:<password>@<cluster>/?retryWrites=true&w=majority"Key pieces:
src/persistence/entities/User.tsdefines a MongoDB-backed TypeORM entity with@Entity("users"),@ObjectIdColumn() _id, and@Column()fields foremail,password, and optionalname.src/persistence/repositories/UserRepository.tsextendsMongoRepository<User>and demonstrates bothuseMongoCollection(...)anduseMongoClient(...)helpers.src/persistence/repositories/PagingUserRepository.tsextendsMongoPagingAndSortingRepository<User>for page/cursor pagination.src/persistence/users.init.tsprovides demo seed data loaded byUserServicewhen the collection is empty.src/persistence/listeners/GlobalEntityEventListener.tslogs entity and transaction lifecycle events.src/persistence/listeners/UserEntityEventListener.tslogs user inserts and callsGreetingService.sayHello(...)after insertion.
Unlike the plain SQL-backed Express sample, this directory has no migrations/ folder, no custom naming strategy, and no datasource-override configuration under src/persistence/. That matches this MongoDB setup: the sample demonstrates a schemaless/document flow instead of SQL migrations.
Authorization is enabled with @EnableAuthorization(LoggedInUserResolver, DefaultAuthorizationResolver).
src/auth/LoggedInUserResolver.tsis a demoCurrentUserCheckerthat logs access and returns a hard-coded user object.src/auth/DefaultAuthorizationResolver.tsis a demoAuthorizationCheckerthat logs checks and authorizes against a hard-codedroles: ["USER", "ADMIN"]user.POST /api/v1/users/uses@Authorized().
This authorization flow is sample-only and is not connected to Firebase Auth.
src/middlewares/LoggingMiddleware.tsuses@Middleware({type: "before"})to log every incoming request.src/middlewares/ErrorMiddleware.tsuses@ErrorHandler()to return JSON errors shaped as{message, statusCode}.app.defaultErrorHandleris set tofalse, so the custom error middleware is the intended handler.src/config/SecurityConfiguration.tsaddshpp(),helmet(), and disables Express'x-powered-byheader.src/config/ServerConfiguration.tsmaps configuredcookie,cors,session, andmultipartsettings into Express server options.src/config/ClassTransformConfiguration.tsshows class-transform configuration withexposeAllstrategies while globally disabling the transformer.src/config/AppConfigProperties.tsbinds theappsection fromapp-config.yamlinto a typed configuration object.
src/services/schedulers.component.ts defines three scheduled jobs:
@Scheduler("*/1 * * * *")— every minute@Scheduler("*/5 * * * *")— every five minutes@Scheduler("0 9 * * *")— every day at 09:00
Each job only logs its execution time.
src/clients/MicroserviceHttpClient.ts demonstrates the HTTP starter with:
@HttpClient({ baseURL: "https://jsonplaceholder.typicode.com", timeout: 5000, httpLogging: true })UserService.findExternalUsers()callingGET /userson that upstream service
From package.json:
pnpm dev— run the app withNODE_ENV=developmentandnodemonpnpm start— clean, build, then rundist/server.jspnpm start:prod— build, then run in production modepnpm build— compile withtsc -p tsconfig.build.jsonpnpm postbuild— run Node-Boot AOT generationpnpm clean:build— removedist/pnpm lint/pnpm lint:fix— run ESLintpnpm format/pnpm format:fix— run Prettierpnpm test/pnpm test:coverage— run the test suitepnpm gen:schema:test— run the Node-Boot model schema generator scriptpnpm nodeboot:update— update@nodeboot/*workspace dependencies
Compared with samples/sample-express, this variant adds @nodeboot/starter-firebase, firebase-admin, and mongodb, and replaces the SQL/SQLite-oriented setup used there.
MIT