🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

hello-node-cli

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hello-node-cli

使用 node 编写 cli 工具

demo
Source
npmnpm
Version
1.1.0
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

hello-node-cli

使用 node 编写 cli 工具

遇到的问题

  • 提示没有权限

给执行权限:chmod +x index.js

  • 添加执行环境

#!/usr/bin/env node

文件第一行,然后 ./index.js 相当于 node index.js

  • 希望在控制台执行jack命令,然后执行node ./index.js,如何设置?

packages.json 添加bin

"bin":{
    "jack": "index.js"
  },

在控制台执行 jack 就是执行 node ./index.js

执行试试: jack

提示zsh: command not found: jack, 如何解决? 把 npm 添到全局。

  • 如何本地测试 npm?

npm link 会将本 npm 依赖添加到全局 node_modules 里,再jack, jack 命令变绿。

  • 如何移除 link 的 npm?

npm rm -g pkg-name

  • 发布一个测试版本

npm publish --tag demo

发布后查看版本信息:

因为发布的第一个版本,是最新版,也是 demo 版本。

发布后移除本地的测试包npm rm -g hello-node-cli,让使用npx测试是否可用。

npx hello-node-cli

可用,一个 node-cli 开发、发布完成,后续添加其他功能。

Keywords

node-cli

FAQs

Package last updated on 08 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts