UNPKG

create-nodeapi-backend

Version:

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.

156 lines (103 loc) 3.83 kB
# 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 1. **Create a New Project:** To use this boilerplate, simply run the following command: ```bash npx create-nodeapi-backend@latest ``` This will automatically generate the project in a new directory and set up all necessary dependencies for you. 2. **Navigate to the Project Folder:** Once the project has been created, navigate to the newly created folder: ```bash cd your-project-folder ``` > ✅ Do not run `npm install` — dependencies are already installed during setup. 3. **Setup Environment** Before running the application, make sure to set up your environment variables. Copy the `.env.sample` file to `.env`: ```bash cp .env.sample .env ``` Open the `.env` file and update the necessary fields with your credentials. ### Example `.env`: ```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/callback ``` ## How to Run in Development Start the Development Server: For local development, you can start the server using nodemon for automatic restarts: ```bash npm run dev ``` Once the server is running, you can access your API at: ```bash http://localhost:3010 ``` or any of your specified open port ### 🔐 Google OAuth Endpoint Use the following route to initiate Google OAuth login: ```bash http://localhost:3010/v1/googleOauth/google ``` This will redirect the user to sign in via their Google account. ## How to Run in Production 1. **Build the Application:** ```bash npm run build ``` 2. **Start the Production Server:** ```bash npm start ``` > Ensure your `.env` values are configured for the production environment. --- ## 🚀 Deploy to Vercel (Optional) To deploy to **Vercel**, simply: 1. Push your project to a GitHub repository. 2. Go to [Vercel](https://vercel.com) and connect your GitHub account. 3. 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: ```bash vercel --prod ``` ## License MIT License. See the LICENSE file for details.