diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..2bc0f47 --- /dev/null +++ b/.env.example @@ -0,0 +1,28 @@ +PORT=YOUR_PORT + +MONGO_URI=YOUR_MONGODB_URL +DB_NAME=YOUR_DATABASE_NAME + +NODE_ENV=dev +SERVER_MAINTENANCE='false' + +JWT_SECRET=YOUR_SECRET +JWT_EXPIRES_IN=30d # CUSTOMIZE AS PER YOUR CHOICE + +COOKIE_EXPIRES_IN=15 # CUSTOMIZE AS PER YOUR CHOICE + +SMTP_FROM='Example ' # CUSTOMIZE AS PER YOUR CHOICE +SENDGRID_API_KEY=YOUR_SENDGRID_API_KEY + +# Cloudinary +CLOUDINARY_CLOUD_NAME=YOUR_CLOUDINARY_CLOUD_NAME +CLOUDINARY_API_KEY=YOUR_CLOUDINARY_API_KEY +CLOUDINARY_API_SECRET=YOUR_CLOUDINARY_API_SECRET + +# STRIPE CONFIG +STRIPE_API_KEY=YOUR_STRIPE_API_KEY +STRIPE_SECRET_KEY=YOUR_STRIPE_SECRET_KEY + +# GitHub +GITHUB_TOKEN=YOUR_GITHUB_TOKEN +GITHUB_USERNAME=YOUR_GITHUB_USERNAME \ No newline at end of file diff --git a/README.md b/README.md index 7d13385..bb3d277 100755 --- a/README.md +++ b/README.md @@ -32,11 +32,12 @@ This repository contains the source code for a E-commerce API built using Node.j ## Features -- User authentication and authorization. -- CRUD operations for users, jobs, and applications. -- JWT-based authentication for secure API access. -- RESTful API design. -- Written in TypeScript for enhanced maintainability and type safety. +- **User Authentication:** Register, login, and manage user accounts with JWT-based authentication. +- **Product Management:** CRUD operations for products. +- **Shopping Cart:** Add, update, and remove items in the shopping cart. +- **Order Management:** Place orders and view order history. +- **Stripe Payment Gateway:** Integrate Stripe for secure payment processing. +- **MongoDB Integration:** Store and manage data using MongoDB. ## Getting Started @@ -48,6 +49,7 @@ You need to have the following software installed on your computer: - [Node.js](https://nodejs.org/) (LTS version recommended) - [npm](https://www.npmjs.com/), [pnpm](https://pnpm.io/) or [Yarn](https://yarnpkg.com/) package manager +- Stripe account and API keys ### Installation @@ -62,7 +64,7 @@ You need to have the following software installed on your computer: 3. Navigate to the project directory: ```bash - cd portfolio-nextjs + cd ecommerce-api-nodejs ``` 4. Install the project dependencies: @@ -113,33 +115,14 @@ By default, the application will run on port `3000`. You can change the port by ## Deployment -This API can be deployed using various platforms such as Heroku, AWS, Google Cloud Platform, or your own server infrastructure. Here are some general steps to deploy the API: - -1. **Prepare your environment**: Ensure that your deployment environment meets the requirements specified in the Prerequisites section. - -2. **Build the application**: If necessary, build the TypeScript code into JavaScript. You can do this by running: - - ```bash - npm run build - #or - yarn build - ``` - -3. **Configure environment variables**: Set up environment variables similar to how it's done in the local setup. Ensure that you provide appropriate values for your deployment environment. - -4. **Deploy the application**: Deploy the built application to your chosen platform. Each platform may have its own deployment process. Refer to the documentation of your chosen platform for detailed instructions. - -5. **Start the application**: Once deployed, start the application in your deployment environment. This might involve running a command similar to `npm start` or `yarn start`, depending on your setup. - -6. **Monitor the deployment**: Monitor the deployed application for any issues. Make sure that it's running smoothly and handle any errors or performance issues as needed. +This API can be deployed using various platforms such as Vercel, Heroku, AWS, Google Cloud Platform, or your own server infrastructure. Set up environment variables similar to how it's done in the local setup. Ensure that you provide appropriate values for your deployment environment. Deploy the built application to your chosen platform. Each platform may have its own deployment process. Refer to the documentation of your chosen platform for detailed instructions. Monitor the deployed application for any issues. Make sure that it's running smoothly and handle any errors or performance issues as needed. ## Technologies Used - Node.js - Express.js - JavaScript -- MongoDB (or any other database of your choice) -- Stripe +- MongoDB ## Contributing @@ -175,6 +158,6 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file [gmail]: mailto:nkr.nikhil.nkr@gmail.com [repo]: https://github.com/nixrajput/ecommerce-api-nodejs -[issues]: https://github.com/nixrajput/ecommerce-api-nodejs +[issues]: https://github.com/nixrajput/ecommerce-api-nodejs/issues [pulls]: https://github.com/nixrajput/ecommerce-api-nodejs/pulls [license]: https://github.com/nixrajput/ecommerce-api-nodejs/blob/master/LICENSE.md diff --git a/src/server.js b/src/server.js index aac1cc7..bcea5df 100755 --- a/src/server.js +++ b/src/server.js @@ -8,8 +8,10 @@ const app = runApp(); // Config if (process.env.NODE_ENV !== "production" || process.env.NODE_ENV !== "prod") { require("dotenv").config({ - path: "./config.env", + path: "./.env.local", }); + + console.log("[.env]: env values loaded"); } // Cloudinary Setup @@ -62,7 +64,6 @@ const connectToDatabase = function () { console.log(`[server] running on port: ${port}`); }); - setTimeout(() => { server.close(); connectToDatabase(); @@ -144,9 +145,7 @@ const connectToDatabase = function () { app.listen(port, (err) => { if (err) { - console.log( - `[server] could not start http server on port: ${port}` - ); + console.log(`[server] could not start http server on port: ${port}`); return; } console.log(`[server] running on port: ${port}`); @@ -155,4 +154,3 @@ const connectToDatabase = function () { connectToDatabase(); } })(); -