Files Manager is a file management application built with Node.js, Express.js, MongoDB, and Redis. It provides a RESTful API for managing files, users, authentication, and file metadata.
- User authentication using JWT (JSON Web Tokens)
- File upload and storage
- File metadata management
- File publishing and unpublishing
- Image thumbnail generation
- Redis caching for improved performance
Read or watch:
- Node JS getting started
- Process API doc
- Express getting started
- Mocha documentation
- Nodemon documentation
- MongoDB
- Bull
- Image thumbnail
- Mime-Types
- how to create an API with Express
- how to authenticate a user
- how to store data in MongoDB
- how to store temporary data in Redis
- how to set up and use a background worker
- Editor: I used Visual Studio Code, you may use Vi, Vim, Emacs, or any other preferred editor.
- All files will be interpreted/compiled on Ubuntu 18.04 LTS using node (version 12.x.x)
- All files should end with a new line
Here are the tasks and corresponding files with links to the repository:
-
Redis utils
- File:
utils/redis.js - Link to file
- File:
-
MongoDB utils
- File:
utils/db.js - Link to file
- File:
-
First API
- File:
server.js - Link to file
- File:
-
Create a new user
- File:
routes/users.js - Link to file
- File:
-
Authenticate a user
- Files:
routes/index.jscontrollers/AuthController.js
- Link to routes file
- Link to controller file
- Files:
-
First file
- Files:
routes/files.jscontrollers/FilesController.js
- Link to routes file
- Link to controller file
- Files:
-
Get and list file
- Files:
routes/files.jscontrollers/FilesController.js
- Link to routes file
- Link to controller file
- Files:
-
File publish/unpublish
- Files:
routes/files.jscontrollers/FilesController.js
- Link to routes file
- Link to controller file
- Files:
-
File data
- Files:
routes/files.jscontrollers/FilesController.js
- Link to routes file
- Link to controller file
- Files:
-
Image Thumbnails
- Files:
routes/files.jscontrollers/FilesController.jsworker.js
- Link to routes file
- Link to controller file
- Link to worker file
- Files:
This structure should help navigate the repository and locate specific files related to each task.
utils/: Contains utility classes for Redis and MongoDB.routes/: Contains route definitions.controllers/: Contains controller logic for handling requests.worker.js: Worker script for processing background tasks.package.json: Configuration file for Node.js dependencies..eslintrc.js: ESLint configuration file.babel.config.js: Babel configuration file.
- Clone the repository:
git clone https://github.com/Reliccode/alx-files_manager.git- Install dependencies:
cd alx-files_manager
npm install- Set up environment variables:
Create a '.env' file in the root directory and specify the following variables:
PORT=3000
MONGO_URI=mongodb://localhost:27017/alx-files-manager
JWT_SECRET=your_jwt_secret
REDIS_HOST=localhost
REDIS_PORT=6379Make sure to replace your_jwt_secret with your desired JWT secret key.
- Run the application (Start the server):
npm startThe API endpoints can be accessed using tools like curl or Postman.
For example, to authenticate a user:
curl 0.0.0.0:5000/connect -H "Authorization: Basic Ym9iQGR5bGFuLmNvbTp0b3RvMTIzNCE="- Users
- POST /api/users/register: Register a new user
- POST /api/users/login: Authenticate a user
- Files
- POST /api/files/upload: Upload a file
- GET /api/files/:id: Get file metadata by ID
- GET /api/files/:id/data: Get file data by ID
- PUT /api/files/:id/publish: Publish a file
- PUT /api/files/:id/unpublish: Unpublish a file
- GET /api/files/:id/thumbnail: Get image thumbnail by ID
This project is licensed under the MIT License - see the LICENSE file for details.