npm installin root directory- create
.envfile in root directory 2a. add PORT to .env file 2b. add DATABASE_URL to .env file- Copy the connection string from MongoDB and add it to the .env file as shown:
2c. add SECRET_KEY to .env file
DATABASE_URL = mongodb://localhost:27017/ - To generate a key:
node -e "console.log(require('crypto').randomBytes(64).toString('base64'))"
- Copy the connection string from MongoDB and add it to the .env file as shown:
npm run dev
Postman for testing API endpoints
1. Create an environment in Postman
Add the following variables to the environment with default type & no values:
- 'sessionId'
Save the environment, and set it as the active environment.
2. Adding requests to test
Create a new collection in Postman, and add the following requests to test the API endpoints.
Add a new request to the collection, and set the request type to POST with the following URL:
{your_server_url}/api/session/create
Go to the Body tab, and select x-www-form-urlencoded. Add the following keys with their respective values:
expiry
password
Go over to Tests tab, and add the following code:
let res = pm.response.json()
let sessionId = res.sessionId;
pm.environment.set("sessionId", sessionId);
Add another request called 'upload', and set the request type to POST with the following URL:
{your_server_url}/api/files/upload/{{sessionId}}
Go to the Body tab, and select form-data. Add their respective keys with their respective values.