create-nodeapi-backend
v1.6.3
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: Integration with MongoDB using Mongoose for database management.
- JWT Authentication: User authentication using JSON Web Tokens (JWT).
- Nodemailer: Send emails via SMTP with Nodemailer.
- Firebase Integration: Firebase setup for cloud functions and storage.
- Node-cron: Task scheduling with cron jobs.
- Google OAuth: Sign in with Google using OAuth 2.0.
- Serverless Support: Preconfigured for deployment on Vercel or any serverless platform.
- Validation: Using Joi for input validation.
How to Install
Create a New Project:
To use this boilerplate, simply run the following command:
npx create-nodeapi-backend@latestThis will automatically generate the project in a new directory and set up all necessary dependencies for you.
Navigate to the Project Folder:
Once the project has been created, navigate to the newly created folder:
cd your-project-folder✅ Do not run
npm install— dependencies are already installed 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
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.
How 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.
