This guide will walk you through setting up your development environment, configuring environment variables, and registering an admin user for your application. It also includes deployment instructions for Render and links to additional resources.
In your project's root directory, create a new file named
.env
.env
file should never be
committed to version control. Make sure to add it to your
.gitignore
file.
Add the following configuration to your .env
file:
NODE_ENV=development PORT=5000 MONGODB_URI=mongodb+srv://your_username:your_password@cluster0.xxxxx.mongodb.net/your_database?retryWrites=true&w=majority DB_PASSWORD=your_mongodb_password JWT_SECRET=secretkey
You can find your connection string in MongoDB Atlas:
Example: Where to find your MongoDB connection string in Atlas
This is the password you created when setting up database access:
Example: Database user password setup in MongoDB Atlas
NODE_ENV=development PORT=5000 MONGODB_URI=mongodb+srv://devuser:SecurePass123@cluster0.0aoioxg.mongodb.net/myappdb?retryWrites=true&w=majority DB_PASSWORD=SecurePass123
Note how the password appears in both MONGODB_URI and DB_PASSWORD in this example.
If you don't already have a MongoDB Atlas cluster set up, follow our comprehensive guide:
View MongoDB Atlas Setup Guidenode -v
npm install
Run your Node.js application with the configured environment variables:
node Server.js
Send a POST request to the following endpoint to register an admin user:
Endpoint:
http://localhost:5000/api/admin/register
Method: POST
Headers:
Content-Type: application/json
Request Body (JSON):
{ "userName": "admin", "password": "admin", "email": "admin@gmail.com" }
You can make this request using Hoppscotch:
http://localhost:5000/api/admin/register
Content-Type: application/json
On successful registration, you should receive a response similar to:
{ "message": "Admin created successfully", "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "admin": { "id": "68a0319b8774739f868b679a", "userName": "YourUserName", "email": "YourEmail@gmail.com" } }
http://localhost:5000/admin
npm install
node Server.js
When hosting your backend on Render's free tier, please be aware that:
For permanent image storage, you need to integrate with a cloud storage provider:
To implement cloud storage:
.env
file:
# Example for AWS S3 AWS_ACCESS_KEY_ID=your_access_key AWS_SECRET_ACCESS_KEY=your_secret_key AWS_REGION=your_region AWS_BUCKET_NAME=your_bucket_name