This is a README file serving as a mini documentation of the challenge project that I worked on in the allowed time frame.
- 👨🏻💻 Author: Rui Hu (@logreg-n-coffee)
- 🌱 Date of Reception: April 15, 2023 7:58 MST (Phoenix, AZ, USA)
- 🌳 Date of Delivery: by April 17: 2023 7:58 MST (Phoenix, AZ, USA)
Please let me know if you have any questions or suggestions. Thank you. 🥳
Install the packages and start:
npm install && npm start
In your browser, get the sample file:
- http://localhost:3000/files/a6a13488-b469-4488-ad94-9c2391bece68
- http://127.0.0.1:3000/files/a6a13488-b469-4488-ad94-9c2391bece68
- Download or clone the repository.
- Locate to the root directory of the project.
- Install the required dependencies by running
npm install
. - Configure environment variables by modifying the
.env
file in the root folder. (optional) - Start the API server using the
npm start
command - Run unit and integration tests using the
npm test
command
To run for the first time:
npm install
To start:
npm start
To run Existing Test:
npm test
The following are the sample requests and responses. Please use the API testing tools as you wish. I usually use Postman to test my APIs. The following is a screenshot of my Postman settings.
Upload a file to the server. The API will return a JSON object containing public and private keys for future reference.
POST /files
Content-Type: multipart/form-data
Content-Disposition: form-data; name="file"; filename="example.txt"
Content-Type: text/plain
< ./path/to/example.txt
HTTP/1.1 201 Created
Content-Type: application/json
{
"publicKey": "a6a13488-b469-4488-ad94-9c2391bece68",
"privateKey": "6603273e-413b-4e04-a106-2085ff7de04c"
}
Download a file from the server. The API will return the content of the file.
GET /files/a6a13488-b469-4488-ad94-9c2391bece68
HTTP/1.1 200 OK
Content-Type: text/plain
This is the content of the uploaded file.
Delete a file from the server using its private key.
DELETE /files/6603273e-413b-4e04-a106-2085ff7de04c
HTTP/1.1 200 OK
Content-Type: application/json
{
"message": "The file has been successfully deleted"
}
I attempted the project within the limited timeframe. Due to limited time, I have documented possible improvements to my project.
- Error handling and logging:
- Enhance error handling throughout the application to provide better debugging information and handle edge cases.
- Consider using a logging library to log important events and errors.
- Security:
- Implement security best practices for API
- add an authentication layer to protect the endpoints,
- use helmet middleware for setting various HTTP headers, and
- sanitize user inputs to prevent potential attacks.
- Implement security best practices for API
- Caching:
- Implement caching for frequently accessed files to improve performance
- Use libraries like redis for in-memory caching or
- memory-cache for a simpler caching mechanism.
- Implement caching for frequently accessed files to improve performance
- Performance optimization:
- Analyze and optimize the performance of the application.
- Use profiling tools like
node --inspect
or - libraries like
clinic
to identify performance bottlenecks and optimize the code.
- Use profiling tools like
- Analyze and optimize the performance of the application.
- Scalability:
- Consider deploying the application to a cloud provider like AWS, Google Cloud, or Microsoft Azure.
- Make it easier to scale the application as needed, providing better availability and reliability.
- Consider deploying the application to a cloud provider like AWS, Google Cloud, or Microsoft Azure.
- Continuous Integration/Continuous Deployment (CI/CD):
- Set up a CI/CD pipeline for the project using services like
- GitHub Actions,
- GitLab CI/CD, or
- Jenkins.
- This will help automate testing, building, and deploying the application.
- Ensure that the code remains stable and up-to-date.
- Set up a CI/CD pipeline for the project using services like
meldcx-code-challenge/
|-- src/
| |-- config/
| | |-- index.js
| |-- storage/
| | |-- index.js
| | |-- local-storage.js
| | |-- google-cloud-storage.js
| |-- api/
| | |-- index.js
| |-- utils/
| | |-- index.js
| |-- app.js
|-- test/
| |-- integration/
| | |-- api.test.js
| |-- unit/
| | |-- storage/
| | | |-- local-storage.test.js
| | | |-- google-cloud-storage.test.js
| |-- sample-file.txt
|-- .env
|-- .env.example
|-- .gitignore
|-- package.json
|-- package-lock.json
|-- README.md
|-- postman-sample.png