npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

app-lib-node

v1.0.34

Published

nodejs工具类库-【app-lib-node】

Readme

二、功能描述

三、注意事项

1: mack运行demo报异常,需要mac安装powershell let isExistPort = res.stdout.toString();

六、API

Constants

Functions

NODE_INNER_MODULES

nodejs 内置所有模块

  • 常用于 webpack 编译 umd 排除使用

Kind: global constant

isExistFile(path) ⇒ boolean

同步判断磁盘文件是否存在

Kind: global function
Returns: boolean - 是否存在 true 存在 false 不存在

| Param | Type | Description | | --- | --- | --- | | path | string | 相对路径 |

resolve(pathName) ⇒ string

相对路径获取的据对路径

Kind: global function
Returns: string - 据对路径地址

| Param | Type | Description | | --- | --- | --- | | pathName | string | 相对路径地址 |

isGlobalInstall() ⇒ boolean

判断当前命令是否未全局安装

  • 向上两层判断是否存在 node.exe

Kind: global function
Returns: boolean - 是否为全局安装

isExistBin(relativePath, name) ⇒ boolean

是否存在 bind

Kind: global function
Returns: boolean - 是否存在 bin

| Param | Type | Description | | --- | --- | --- | | relativePath | string | 相对路径 | | name | string | 组件名称 |

getBin(compnentName) ⇒ string

获取 nodejs 的 bin 执行位置

Kind: global function
Returns: string - 组件的路径

  • tips
  1. 开发模式直接获取当前目录的下的指定配置路径
  2. 局部查找
  3. 全局组件内部
  4. 全局外部

| Param | Type | Description | | --- | --- | --- | | compnentName | string | 组件名称 |

isDev() ⇒ boolean

是否为 app 定义的开发模式

Kind: global function
Returns: boolean - 是否为开发模式

  • tips
  1. cross-env 中不支持中划线 eg:APP-MODLE
  2. MODE 或在 M 值为 DEV 或者 DEVELOP, develop,dev
  3. 主要用于该工程的开发模式

getTemplate() ⇒ string

获取模版位置

Kind: global function
Returns: string - 模版位置

readFile(path, options) ⇒ promise

读文件【异步】

Kind: global function
Returns: promise - data | 读取的文件内容

  • tips
    1. string|Buffer|URL|integer filename or file descriptor
    2. https://nodejs.org/docs/latest-v13.x/api/fs.html#fs_fs_readfile_path_options_callback

| Param | Type | Description | | --- | --- | --- | | path | string | Buffer | URL | integer | 文件路径 | | options | object | ndoejs 的配置 |

readFileSync(path, options) ⇒ string

读文件【同步】

Kind: global function
Returns: string - 文件内容

  • tips
    1. string|Buffer|URL|integer filename or file descriptor
    2. https://nodejs.org/docs/latest-v13.x/api/fs.html#fs_fs_readfile_path_options_callback

| Param | Type | Description | | --- | --- | --- | | path | string | Buffer | URL | integer | 文件路径 | | options | object | ndoejs 的配置 |

writeFile(path, options) ⇒ promise

写文件【异步】

Kind: global function
Returns: promise - data | 读取的文件内容

  • tips
    1. string|Buffer|URL|integer filename or file descriptor
    2. https://nodejs.org/docs/latest-v13.x/api/fs.html#fs_fs_readfile_path_options_callback

| Param | Type | Description | | --- | --- | --- | | path | string | Buffer | URL | integer | 文件路径 | | options | object | ndoejs 的配置 |

writeFileSync(path, options) ⇒ string

写文件【同步】

Kind: global function
Returns: string - 文件内容

  • tips
    1. string|Buffer|URL|integer filename or file descriptor
    2. https://nodejs.org/docs/latest-v13.x/api/fs.html#fs_fs_readfile_path_options_callback

| Param | Type | Description | | --- | --- | --- | | path | string | Buffer | URL | integer | 文件路径 | | options | object | ndoejs 的配置 |

writeFileSyncAndCreate(path, options) ⇒ string

写文件【同步】不存在文件夹则创建

Kind: global function
Returns: string - 文件内容

| Param | Type | Description | | --- | --- | --- | | path | string | Buffer | URL | integer | 文件路径 | | options | object | ndoejs 的配置 |

isExistDir(path) ⇒ boolean

是否为文件夹

Kind: global function
Returns: boolean - 是否为文件夹

| Param | Type | Description | | --- | --- | --- | | path | string | 文件夹路径 |

getParentDir(path, dirName, layer) ⇒ object

获取指定路径的父级目录包含的文件夹名

Kind: global function
Returns: object - 找的父级的路径

  • example
 {
  path : null 标识不存在 否则标识存在的路径
  layer: number 查到的层级
 }

| Param | Type | Default | Description | | --- | --- | --- | --- | | path | string | | 当前的路径 | | dirName | string | | 文件夹名称 | | layer | number | 0 | 当前目录到找到目录目录的层级 |

copyFile(src, dest, isForce, flags) ⇒ promise

复制文件

  • 不存在目录则创建 但是一定是两边都包含文件 否则会报错 operation not permitted, copyfile xxx

Kind: global function

| Param | Type | Default | Description | | --- | --- | --- | --- | | src | string | | 源地址 | | dest | string | | 目标地址 | | isForce | string | | 文件存在是否强制覆盖 默认 false | | flags | number | 0 | 复制标识 |

copyFileSync(src, dest)

单文件强制复制文件

不存在目录则创建 但是一定是两边都包含文件 否则会报错 operation not permitted, copyfile xxx

Kind: global function

| Param | Type | Description | | --- | --- | --- | | src | string | 源文件路径 | | dest | string | 目标文件路径 |

mkdir(path, options) ⇒ null

创建目录【同步】

Kind: global function
Returns: null - 无返回

  • tips
  1. https://nodejs.org/docs/latest-v13.x/api/fs.html#fs_fs_mkdir_path_options_callback

| Param | Type | Description | | --- | --- | --- | | path | string | 路径 | | options | object | 参数 |

yesOrNo(tips, [defaultValue]) ⇒ promise

录取用户输入

Kind: global function
Returns: promise - 读取结果

| Param | Type | Default | Description | | --- | --- | --- | --- | | tips | string | | 提示信息 | | [defaultValue] | string | "yes" | 默认值 |

readline(tips, isAlowEmpty) ⇒ promise

录取用户输入

Kind: global function
Returns: promise - 读取结果

| Param | Type | Default | Description | | --- | --- | --- | --- | | tips | string | | 提示信息 | | isAlowEmpty | boolean | false | 运行为空 |

updateContent(options) ⇒ string

文本中添加或者覆盖指定内容

Kind: global function
Returns: string - 新文本

| Param | Type | Description | | --- | --- | --- | | options | object | 参数 | | [options.content] | object | 文本内容 | | [options.startflag] | object | 开始标识 | | [options.endFalg] | object | 结束标识 | | [options.appContent] | object | 最佳或者替换的内容 | | [options.isRepalce] | object | 是否为替换 默认是追加 false | | [options.isStart] | object | 不存在时 追加最前面 默认是后面 | | [options.isInnerStart] | object | 追加文档时 追加在 heade 与 oldcontent 之间 默认在尾部 | | [options.space] | object | 与标识符的间隔 | | [options.newHeader] | object | 不存在时候 添加头部内容 |

getRootPath(relativePath) ⇒ string

获取安装类库的据对目录

Kind: global function
Returns: string - 主目录路径

| Param | Type | Default | Description | | --- | --- | --- | --- | | relativePath | string | "./" | 执行文件的相对目录 默认 ../../ |

getMainPath(relativePath) ⇒ string

当前安装 或者执行命令 的路径

Kind: global function
Returns: string - 新路径

  • tips 默认执行的 bin 文件 在工程目录的下两层 到当前组件的跟目录层 上一侧目录都为当前组件的目录

| Param | Type | Default | Description | | --- | --- | --- | --- | | relativePath | string | "../../" | 相对路径 |

getBinPath() ⇒ string

获取当前组件 bin 的路径

Kind: global function
Returns: string - bin 路径

readdirSync(path) ⇒ array

读取目录【同步】

Kind: global function
Returns: array - 文件目录

| Param | Type | Description | | --- | --- | --- | | path | string | 目录路径 * @param {object} options 读取配置 |

delDir(path)

嵌套删除子文件夹和文件

Kind: global function

| Param | Type | Description | | --- | --- | --- | | path | string | 路径 |

delFile(path)

删除文件【同步】

Kind: global function

| Param | Type | Description | | --- | --- | --- | | path | string | 文件路径 |

isSysUsePort(port) ⇒ boolean

系统判断端口使用 // TODO 采用静态编译方式 处理静态文件 // TODO mack 上无法判断

Kind: global function
Returns: boolean - 事都被占用

| Param | Type | Description | | --- | --- | --- | | port | number | 端口号 |

getCanUsePort(port) ⇒ number

获取到能够使用的端口

  • 动态自增的方式 直到可用的端口

Kind: global function
Returns: number - 可用的端口

| Param | Type | | --- | --- | | port | number |

copyProjectFile(from, to, defaultIsSucess)

复制文件【异步】

Kind: global function

| Param | Type | Default | Description | | --- | --- | --- | --- | | from | string | | 相对发布组件的目录 | | to | string | | 相对生成的目录 | | defaultIsSucess | boolean | 0 | 不存在文件的时候是否默认为成功 默认为成功 |

copyProjectFileSync(from, to, defaultIsSucess)

复制文件【同步】

Kind: global function

| Param | Type | Default | Description | | --- | --- | --- | --- | | from | string | | 相对发布组件的目录 | | to | string | | 相对生成的目录 | | defaultIsSucess | boolean | 0 | 不存在文件的时候是否默认为成功 默认为成功 |

copyFolder(source, target)

嵌套复制文件夹【同步】

Kind: global function

| Param | Type | Description | | --- | --- | --- | | source | string | 源路径 | | target | string | 目标路径 |

getLocalIP() ⇒ string

获取本机 IP

  • windows 验证 其他环境还未验证

Kind: global function
Returns: string - ip 地址

  • tips
  1. 目前值返回 IPv4 后续可以扩展 IPv6