CzLink
is a Node.js package for creating and serving zip files from specified input paths. It includes basic functionality to zip files or directories and serve them over HTTP with progress updates.
To install CzLink
, run:
npm install czlink
First, set up the zip process and start the server:
const czlink = require('czlink');
czlink({
sourceFolder: './data', // Folder to be zipped
outputFolder: './backups', // Folder where the zip files will be saved
expressAlr: false, // If true, it will not start the express server
port: 4000 // Custom port for the Express server
});
Once the server is running, you can download the zip file using the following URL:
http://localhost:PORT/download/backup.zip
Replace PORT
with the port number specified in the czlink()
function call.
If an Express server is already running, you can serve the zip files without starting a new server by setting expressAlr: true
in the options:
const czlink = require('czlink');
czlink({
sourceFolder: './data', // Folder to be Backup
outputFolder: './backups', // Folder where the zip files will be saved
expressAlr: true, // If true, it will not start the express server
port: 4000 // Custom port for the Express server
});
Then, in your existing Express server, add this route to serve the zip file:
let outputFolder = "your_output_folder_goes_here";
app.use('/download', express.static(outputFolder));
This will allow your server to serve the zip files created by CzLink
at the /download
endpoint.
Sets up the zip process and optionally starts an Express server.
sourceFolder
(string): The path to the folder or directory that will be zipped.outputFolder
(string): The path to the folder where the zip files will be saved.expressAlr
(boolean): Iftrue
, it will not start a new Express server but expects an existing one to handle file downloads.port
(number, optional): The port number to start the Express server on ifexpressAlr
isfalse
(default is3000
).
Starts the download of the zip file.
- The zip file will be named
backup.zip
and stored in theoutputFolder
. - The
outputFolder
is recreated each time the zip process runs. - The server logs zip progress in the console.
- If an Express server is already running and
expressAlr
istrue
, you can use theoutputFolder
path to serve the zip file from your existing server.
This project is licensed under the MIT License.
Made by Coneiz.