跳转到内容

@ergate/nodejs包

该方法会替换掉原有文件内容

/**
* @param filePath 文件路径,自动递归创建所属目录
* @param content 写入内容
*/
export function writeFile(filePath: string, content: any) {}

不会替换原有内容,在原有内容后追加。自动增加末尾行。

/**
* @param filePath 文件路径
* @param content 追加内容
*/
export function appendFile(filePath: string, content: string) {}

递归创建指定文件夹路径,保证路径可用

/**
* @param path 文件夹路径
*/
export function ensureDirectory(path: string) {}
/**
* @param path 路径
*/
export function pathExists(path: string): boolean {}
/**
* @param path 路径
*/
export function deletePath(path: string) {}

部分时候@types/multer不生效,故导出与其类型相同的自定义类型

export interface UploadFile {
/** Name of the form field associated with this file. */
fieldname: string;
/** Name of the file on the uploader's computer. */
originalname: string;
/** Value of the `Content-Type` header for this file. */
mimetype: string;
/** Size of the file in bytes. */
size: number;
/**
* A readable stream of this file. Only available to the `_handleFile`
* callback for custom `StorageEngine`s.
*/
stream: Readable;
/** `DiskStorage` only: Directory to which this file has been uploaded. */
destination: string;
/** `DiskStorage` only: Name of this file within `destination`. */
filename: string;
/** `DiskStorage` only: Full path to the uploaded file. */
path: string;
/** `MemoryStorage` only: A Buffer containing the entire file. */
buffer: Buffer;
}

返回当前机器在局域网中的IPV4地址

export function getLocalIP() {}

检测给定端口是否被应用程序监听

/**
* @param port 端口号
* @param host 主机,默认 127.0.0.1
* @returns true=被占用,false=空闲
*/
export function isPortUsed(port: number, host = '127.0.0.1'): Promise<boolean> {}

随机返回一个[minPort, maxPort]区间内未被其他程序监听的端口号,常用于服务启动时指定端口号

/**
* @param minPort 最小端口,默认 1024
* @param maxPort 最大端口,默认 49151
* @param host 检测主机
* @returns 空闲端口号
*/
export async function getRandomFreePort(
minPort = 1024,
maxPort = 49151,
host = '127.0.0.1',
): Promise<number> {}