express-ts-skeleton
Version:
This is a skeleton(boiler plate) for nodejs, express and typescript.
45 lines (44 loc) • 2.28 kB
TypeScript
import { Response } from "express";
import { PathLike } from "fs";
export declare class responseHelper {
constructor();
/**
* Handles file download by streaming a file to the response and optionally
* deletes the file after the download completes.
* @param {{ filePath: PathLike; fileName: string; willDelete: boolean }} result - An object containing file information:
* - `filePath` (PathLike): The path to the file to be downloaded.
* - `fileName` (string): The name that will be set for the downloaded file.
* - `willDelete` (boolean): A flag indicating if the file should be deleted after download.
* @param {Response} res - The Express response object used to send the file to the client.
* @returns {void} Sends the file in the response, sets headers, and handles any errors that occur during access, streaming, or deletion.
* @fires Response#finish - Triggered when the response is finished, indicating download completion.
* @fires Response#close - Triggered when the connection is closed, which optionally deletes the file if `willDelete` is true.
*/
protected download(result: {
filePath: PathLike;
fileName: any;
willDelete: any;
}, res: Response): void;
/**
* Renders a view with the specified content.
* @param {{ view: string; content: object }} result - An object containing:
* - `view` (string): The name of the view template to render.
* - `content` (object): The data to pass to the view for rendering.
* @param {Response} res - The Express response object used to render the view.
* @returns {void} Sends the rendered view in the response.
*/
protected render(result: {
view: any;
content: any;
}, res: Response): void;
/**
* Sends a JSON response with a specified status code.
* @param {{ statusCode: number }} result - An object containing:
* - `statusCode` (number): The HTTP status code to set for the response.
* @param {Response} res - The Express response object used to send the JSON response.
* @returns {void} Sends the JSON response with the specified status code.
*/
protected json(result: {
statusCode: number;
}, res: Response): void;
}