This is a REST API application for uploading files to either a local server or to the cloud using Cloudinary. It provides endpoints for uploading images and getting a list of uploaded images.
In this build, I used Node.js, Express.js, MongoDB, Mongoose, TypeScript, Morgan, Dotenv, Express-FileUpload, Cloudinary.
Download and run npm install, then create a .env file at the root of the project and set the following environment variables:
PORT=
MONGO_URI=
IMAGE_MAX_SIZE=if you want to upload images on Cloudinary in additon create this environment variables:
CLOUD_NAME=
CLOUD_API_KEY=
CLOUD_API_SECRET=Mongo uri example:
MONGO_URI=mongodb+srv://giorgi:[email protected]/yourDatabaseName?retryWrites=true&w=majoritythen run npm start.
If you want to save photos in your local server go to api->routes->productRoutes.ts->uncomment commented code lines, and comment out the line of code responsible for saving the photo in the Cloudinary.
POST /api/v1/products/uploads| Parameter | Type | Description |
|---|---|---|
image |
File |
Required. Photo that you want to upload |
POST /api/v1/products| Parameter | Type | Description |
|---|---|---|
name |
string |
Required. Name of your product |
price |
number |
Required. Price of your product |
image |
string |
Required. Image of your product |
GET /api/v1/productsReturns a list of all products.