create-nodeapi-backend
v2.0.0
Published
A powerful Node.js backend boilerplate with Express, MongoDB, Firebase, JWT auth, Nodemailer, cron jobs, input validation (Joi), and serverless support for Vercel. Scaffold a full-featured API backend in seconds.
Maintainers
Readme
create-nodeapi-backend
A simple boilerplate for quickly setting up a Node.js API with Express, MongoDB, JWT authentication, and more. This tool will help you generate a fully functional backend with minimal configuration.
Features
- Express.js: RESTful API with Express for handling routes and middleware.
- MongoDB: Database integration via Mongoose or Prisma ORM.
- JWT Authentication: Secure user login, session management, and JWTs.
- Nodemailer: Preconfigured SMTP mail sending utilities.
- Firebase Integration: Ready-to-go Firebase client configuration.
- Node-cron: Task scheduling out of the box.
- Google OAuth: Complete authentication pipeline using Google OAuth 2.0.
- Serverless Support: Preconfigured files for smooth Vercel deployments.
- Input Validation: Robust Joi/Zod input validation.
Available Templates
When running the generator, you can choose from the following pre-configured project templates:
JavaScript
- Database & ODM: MongoDB with Mongoose
- Bundler: Webpack
- Features: A fully functional JavaScript backend with JWT Auth, OTP verification, password resets, Google OAuth, Sentry logging, and profile uploads.
TypeScript
- Database & ODM: MongoDB with Mongoose
- Bundler: Rollup
- Features: A clean, minimal TypeScript skeleton featuring Sentry, Firebase client, Nodemailer, and database retry logic.
TypeScript with Prisma (MongoDB)
- Database & ORM: MongoDB with Prisma ORM
- Caching & Realtime: Redis integration and WebSockets (
ws) - Bundler: Rollup and esbuild
- Features: An advanced, production-ready CRM/Admin boilerplate. Features a custom Swagger UI documentation page (
/api-docs), Sentry error handlers, roles & permissions (RBAC) middleware, email templating, and bulk emailing jobs.
How to Install
Create a New Project:
To launch the interactive generator, run the following command:
npx create-nodeapi-backend@latestDuring the prompt wizard, you will be asked to choose:
- A project name.
- A template (
JavaScript,TypeScript, orTypeScript with Prisma). - A package manager (
npm,pnpm, orbun).
Navigate to the Project Folder:
cd your-project-folder✅ Note: Dependencies are automatically installed by the CLI using the package manager you chose during setup.
Setup Environment
Before running the application, make sure to set up your environment variables.
Copy the
.env.samplefile to.env:cp .env.sample .envOpen the
.envfile and update the necessary fields with your credentials.
Example .env:
JWT_SECRET=1111111111111111scscsdcsdc
JWT_ACCESS_EXPIRATION_MINUTES=4200
JWT_REFRESH_EXPIRATION_MINUTES=800
NODE_ENV=dev
PORT=3010
SALT=10
MONGODB_USERNAME=username
MONGODB_PASSWORD=password
MONGODB_DATABASE=dbstore
MONGODB_URL=databaseurl
ORIGIN=
SMTP_SERVICE=gmail
SMTP_MAIL=Mmail.com
SMTP_PASSWORD=password
EMAIL_FROM=me.com
API_KEY=a
AUTH_DOMAIN=a
DATABASE_URL=a
PROJECT_ID=a
STORAGE_BUCKET=a
MESSAGING_SENDER_ID=a
APP_ID=a
MEASUREMENT_ID=a
SERVER_ORIGIN=localhost:3010
FRONTEND_ORIGIN=localhost:3000
GOOGLE_CLIENT_ID=your_client_id.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=your_client_secret
GOOGLE_CLIENT_URI=/v1/googleOauth/google/callbackHow to Run in Development
1. Database Setup (Prisma Template Only)
If you chose the TypeScript with Prisma template, you must push your schema to the MongoDB database and seed it before starting:
# Push schema to MongoDB
npm run prisma:push
# Seed the database with default roles and admin users
npm run prisma:seedNote: The seed script creates default users (e.g. [email protected] / password123) to help you get started.
2. Start the Development Server
For local development, you can start the server using nodemon for automatic restarts:
npm run devOnce the server is running, you can access your API at:
http://localhost:3010or any of your specified open port.
🔐 Google OAuth Endpoint
Use the following route to initiate Google OAuth login:
http://localhost:3010/v1/googleOauth/googleThis will redirect the user to sign in via their Google account.
📖 API Documentation (Prisma Template Only)
When running the Prisma template, you can view the interactive Swagger API documentation:
http://localhost:3010/api-docsHow to Run in Production
Build the Application:
npm run buildStart the Production Server:
npm startEnsure your
.envvalues are configured for the production environment.
🚀 Deploy to Vercel (Optional)
To deploy to Vercel, simply:
- Push your project to a GitHub repository.
- Go to Vercel and connect your GitHub account.
- Select the repository and follow the prompts.
Vercel will automatically detect your Node.js setup and deploy your project with minimal configuration.
Or deploy via CLI:
vercel --prodLicense
MIT License. See the LICENSE file for details.
