REST API in Node to load and query CSV
This backend project receives CSV files using a RESTful Node API, saves them locally as files and in MongoDB. It also has an endpoint to query the data saved in the database.
- Node.js
- Express.js
- MongoDB
- Mongoose
- Multer
- CsvtoJSON
- Nodemon
- Docker
- Jest
- Supertest
- Dotenv
*** This backend project should be used with the frontend, located at shaw-csv-frontend, however, it is also a standalone RESTful API, which can be used with Postman/Insomnia or other mean that communicates with HTTP REST endpoints ***
- Get the link of the repository:
[email protected]:arthurborgesdev/shaw-csv-frontend.git
- Clone it as
[email protected]:arthurborgesdev/shaw-csv-frontend.git
on a Terminal - Change directory to it by
cd shaw-csv-frontend
- Run
npm i
on a Terminal
This project can be setup with Docker (preferred way if you don't have MongoDB installed or don't want to install it) or with a locally installed Mongo.
Run docker compose command
docker-compose -f docker-compose.yml up
docker ps
-> Get container ID
docker logs <container id>
-> Print app output
docker exec -it <container id> /bin/bash
-> Get into the container
docker kill <container id>
-> Shutdown the container
- Install MongoDB according to your OS instructions if you don't have it installed
- Run it accordingly to your OS instructions
- Enter in the mongo shell by typing
mongosh
on a Terminal - Create a
root
user withpass
password (Step necessary to match the config for Docker and Nodejs env variable):
use admin
db.createUser(
... {
... user: "root",
... pwd: "pass",
... roles: [ { role: "root", db: "admin" }]
... }
... )
npm run dev
will run nodemon for local testing
npm run test:unit
npm run test:integration
npm run test
POST 127.0.0.1:3000/api/files
multipart/form-data
csv-file: "example.csv"
Return: Loaded CSV as a array of objects
GET 127.0.0.1:3000/api/users?q=term1,term2,term3
queries: term1,term2,term3
Return: Filtered CSV related to the provided queries
👤 Arthur Borges