This is a starter template for a REST API built on Node JS, Express and MongoDB.
Follow the steps below to set up and run the REST API on your local machine.
To get started, clone this repository to your local machine using the following command:
git clone https://github.com/urwah1248/Node-Express-Mongodb-Starter.git
- Navigate to the root folder of the cloned repository.
- Create a new file named
.env
by copying the provided.env.example
file. - Edit the
.env
file and add your MongoDB URI to theMONGODB_URI
variable. It should look something like this:
PORT=3000
MONGODB_URI=mongodb://your-username:your-password@your-host:your-port/your-database
Replace the placeholder values with your actual MongoDB credentials.
Before running the application, you need to install its dependencies. Make sure you have Node.js and npm installed.
- Open a terminal or command prompt.
- Navigate to the root folder of the cloned repository.
- Run the following command to install the required dependencies:
npm install
Once the dependencies are installed and the environment variables are set up, you can start the application. The start
script is used for production, and the dev
script is used for development.
To start the application in production mode, run:
npm start
To start the application in development mode, which uses tools like nodemon for automatic restarts on file changes, run:
npm run dev
The API will be available at http://localhost:3000 by default (you can change the port in the .env
file).