appjx
v1.1.6
Published
A Node.js module to interact with storage APIs using axios and FormData.
Downloads
35
Maintainers
Readme
appJx
Overview
appJx is a powerful and easy-to-use Node.js library designed to simplify file management tasks, including file uploads, updates, deletions, and storage management. Whether you're building a simple application that needs file storage capabilities or a complex system with vault-based file organization, appJx provides a flexible and efficient solution to manage your files with ease.
The library is built to handle various file operations securely and efficiently, ensuring that your file management needs are met without compromising on performance or security.
Features
- File Uploading: Seamlessly upload files to designated vaults, with support for various file types and sizes.
- File Listing: Retrieve a list of files stored within a specific vault, allowing for easy file management and organization.
- File Updating: Update metadata or content of existing files to keep your storage up-to-date.
- File Deletion: Safely remove files from storage when they are no longer needed.
- Vault Management: Access and manage details of storage vaults to keep track of where your files are stored.
These sections provide a clear introduction to what appJx does and highlight its key features, making it easier for users to understand the purpose and capabilities of the package.
Installation
To start using appJx, you can install it via npm or Yarn. Ensure you have Node.js installed on your machine.
npm install appJx
yarn add appJx
Usage
- Importing the Package To use appJx in your project, first import the necessary classes.
For CommonJS (Node.js):
const { FileManager, VaultManager } = require("appJx");
For ES Modules (Node.js):
import { FileManager, VaultManager } from "appJx";
- Setting Up the Client
Create an instance of the Client by providing the base URL of your API and an access key for authentication:
const client = new Client({
baseUrl: "http://localhost:4000",
accessKey: "YtMQ9T0YAUyK-XxRgeI9cpQ2vqjSlN8NHOPSxsdsSmk",
});
- Using the Storage Class
Initialize the Storage class with the client:
const storage = new Storage(client);
Upload a File:
const fileData = Buffer.from("Your file data");
const vaultId = "your-vault-id";
storage
.uploadFile(fileData, vaultId)
.then((fileId) => {
console.log(`File uploaded successfully. File ID: ${fileId}`);
})
.catch((error) => {
console.error(`Error uploading file: ${error.message}`);
});
Retrieving a File List:
storage
.getFileList(vaultId)
.then((fileList) => {
console.log("File List:", fileList);
})
.catch((error) => {
console.error(`Error retrieving file list: ${error.message}`);
});
Updating a File:
const fileId = "your-file-id";
const newFileData = Buffer.from("Updated file data");
storage
.updateFile(fileId, newFileData)
.then(() => {
console.log("File updated successfully.");
})
.catch((error) => {
console.error(`Error updating file: ${error.message}`);
});
Deleting a File:
const fileId = "your-file-id";
storage
.deleteFile(fileId)
.then(() => {
console.log("File deleted successfully.");
})
.catch((error) => {
console.error(`Error deleting file: ${error.message}`);
});
Retrieving Vault Details
storage
.getVaultDetails(vaultId)
.then((vaultDetails) => {
console.log("Vault Details:", vaultDetails);
})
.catch((error) => {
console.error(`Error retrieving vault details: ${error.message}`);
});
Error Handling
appJx provides error messages that are easy to catch and debug. All methods return Promises, so you can handle errors using .catch() or try-catch with async/await.
storage
.uploadFile(fileData, vaultId)
.then((fileId) => {
console.log(`File uploaded successfully. File ID: ${fileId}`);
})
.catch((error) => {
console.error(`Error uploading file: ${error.message}`);
});
API Reference
Client
1 Client(config): Initializes a new client.
- config.baseUrl: The base URL for the API.
- config.accessKey: The access key for authentication.
Storage
- uploadFile(fileData, vaultId): Uploads a file to a specified vault.
- fileData: The file data as a Buffer.
- vaultId: The ID of the vault where the file will be stored.
- getFileList(vaultId): Retrieves a list of files from a specified vault.
- vaultId: The ID of the vault.
- updateFile(fileId, updates): Updates the metadata of a specified file.
- fileId: The ID of the file to be updated.
- updates: An object containing the fields to update.
- deleteFile(fileId): Deletes a specified file.
- fileId: The ID of the file to be deleted.
- getVaultDetails(vaultId): Retrieves details about a specified vault.
- vaultId: The ID of the vault.
license
This project is licensed under the MIT License. See the LICENSE file for more details.
Support
If you have any questions or need help, feel free to reach out by opening an issue or by contacting the project maintainers at [email protected]
Please note that this is just a brief overview of how to use the appJx library. For more details and information about other methods and classes, you can refer to the API Reference section in the documentation.
If you have any questions or need further assistance, feel free to ask.