mds-file-upload is a simple and efficient file upload utility built for Node.js applications. It supports uploading files to a specified folder and managing temporary and permanent storage paths with ease.
- Upload files to a specified folder.
- Temporary file storage option.
- Move files from temporary to permanent storage.
- Delete uploaded files.
- Check for the existence of files or folders.
To install the package, run:
npm install mds-file-upload
Import the MdsFileUpload
class and initialize it with your project's base directory:
import { MdsFileUpload } from "mds-file-upload";
const uploader = new MdsFileUpload(process.cwd());
Uploads a file to the uploads
folder by default or to the temp
folder if specified.
Parameters:
-
infile
(File): The file to upload. -
toTemp
(boolean, optional): Whether to upload to the temporary folder. Defaults tofalse
.
Example:
const file = new File(["content"], "example.txt");
uploader.handleFileUpload(file)
.then(result => console.log("File uploaded:", result))
.catch(err => console.error("Upload failed:", err));
Deletes a file from the uploads
folder.
Parameters:
-
filename
(string): The name of the file to delete.
Example:
uploader.deleteUploadedFile("example.txt")
.then(() => console.log("File deleted."))
.catch(err => console.error("Deletion failed:", err));
Moves a file from the temp
folder to the uploads
folder.
Parameters:
-
filename
(string): The name of the file to move.
Example:
uploader.moveFileToUpload("temp-example.txt")
.then(success => console.log("File moved successfully:", success))
.catch(err => console.error("Move failed:", err));
Checks if a file or folder exists at a specified path.
Parameters:
-
targetPath
(string): The path to check.
Example:
uploader.checkFileOrFolderExists("/path/to/file.txt")
.then(exists => console.log("Exists:", exists))
.catch(err => console.error("Error checking existence:", err));
mds-file-upload/
├── src/
│ ├── index.ts # Main source file
├── dist/ # Compiled output
├── package.json # NPM configuration
├── README.md # Project documentation
└── tsconfig.json # TypeScript configuration
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Commit your changes (
git commit -m 'Add new feature'
). - Push to the branch (
git push origin feature-branch
). - Open a Pull Request.
This project is licensed under the MIT License.
Developed and maintained by Mwero Abdalla.
- GitHub: mwenaro
The source code for this project is available on GitHub:
https://github.com/mwenaro/mds-file-upload
This package follows semantic versioning. Refer to the CHANGELOG for details on updates.