
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
npm-cli-app
Advanced tools
Create project
npm init
Create exectuable script
mkdir bin
Create file cli.js
module.exports = {
run : (args) => {
console.log("running command with ", args);
}
};
Create file bin/npm-cli-app.js
#!/usr/bin/env node
require('../cli').run(process.argv);
Run and check the script file
node bin/npm-cli-app.js hello
# running command with [
# '/Users/me/.nvm/versions/node/v14.5.0/bin/node',
# '/Users/me/projects/npm-cli-app/bin/npm-cli-app.js',
# 'hello'
# ]
Update pakcage.json to include the bin file :
"bin": {
"npm-cli-app": "bin/npm-cli-app.js"
},
Install project locally for testing
npm link
# /Users/me/.nvm/versions/node/v14.5.0/bin/npm-cli-app -> /Users/me/.nvm/versions/node/v14.5.0/lib/node_modules/npm-cli-app/bin/npm-cli-app.js
# /Users/me/.nvm/versions/node/v14.5.0/lib/node_modules/npm-cli-app -> /Users/me/projects/npm-cli-app
Now run and test your command :
npm-cli-app hello
# running command with [
# '/Users/dawn/.nvm/versions/node/v14.5.0/bin/node',
# '/Users/dawn/.nvm/versions/node/v14.5.0/bin/npm-cli-app',
# 'hello'
# ]
Create file src/app.js
module.exports = {
run : (parameters) => {
console.log("running app with : ", parameters)
}
};
Update cli.js
to run app and pass only user provided data
const app = require('./src/app');
module.exports = {
run : (args) => {
app.run(args.slice(2));
}
};
Now run out comamnd again
npm-cli-app hello
# running app with : [ 'hello' ]
publish to npm
npm login
# Enter you username/password
npm publish
FAQs
Creating and publishing cli apps with npm
We found that npm-cli-app demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.