Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
CLI Tools with Node
Search
Henrique Schreiner
November 02, 2016
Programming
0
62
CLI Tools with Node
Learn how you can easily create your own CLI (Command Line Interface) tool with Node.js.
Henrique Schreiner
November 02, 2016
Tweet
Share
More Decks by Henrique Schreiner
See All by Henrique Schreiner
Testando Componentes React com Jest e Enzyme
hmschreiner
0
80
Como convencer seu time a mudar de tecnologia
hmschreiner
2
470
Javascript with Classes
hmschreiner
0
57
Other Decks in Programming
See All in Programming
Kiroの仕様駆動開発から見えてきたAIコーディングとの正しい付き合い方
clshinji
1
210
AIと私たちの学習の変化を考える - Claude Codeの学習モードを例に
azukiazusa1
9
3.6k
AIを活用し、今後に備えるための技術知識 / Basic Knowledge to Utilize AI
kishida
21
5.6k
アセットのコンパイルについて
ojun9
0
120
Android端末で実現するオンデバイスLLM 2025
masayukisuda
1
130
デザイナーが Androidエンジニアに 挑戦してみた
874wokiite
0
280
testingを眺める
matumoto
1
140
250830 IaCの選定~AWS SAMのLambdaをECSに乗り換えたときの備忘録~
east_takumi
0
390
rage against annotate_predecessor
junk0612
0
160
Updates on MLS on Ruby (and maybe more)
sylph01
1
180
アプリの "かわいい" を支えるアニメーションツールRiveについて
uetyo
0
230
Go言語での実装を通して学ぶLLMファインチューニングの仕組み / fukuokago22-llm-peft
monochromegane
0
120
Featured
See All Featured
Building Better People: How to give real-time feedback that sticks.
wjessup
368
19k
Stop Working from a Prison Cell
hatefulcrawdad
271
21k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
229
22k
Optimising Largest Contentful Paint
csswizardry
37
3.4k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
34
6k
How to Ace a Technical Interview
jacobian
279
23k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
580
Building Applications with DynamoDB
mza
96
6.6k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
131
19k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
920
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.4k
Statistics for Hackers
jakevdp
799
220k
Transcript
CLI Tools with Node @hmschreiner
root@hmschreiner : $ whoami # Henrique Schreiner Software Developer at
e-Core @hmschreiner linkedin.com/in/HenriqueSchreiner e-core.com/pt/carreiras
# Creating the Project
root@hmschreiner : ~/my-tool-folder $ npm init name: file-search version: 1.0.0
description: My CLI tool to search files entry point: index.js test command: git repository: keywords: author: Henrique Schreiner license: (ISC)
{ "name": "file-search", "version": "1.0.0", "description": "My CLI tool to
search files", "main": "index.js", "author": "Henrique Schreiner", "license": "ISC" } Is this ok? (yes) root@hmschreiner : ~/my-tool-folder $ npm init
# Editing package.json
{ "name": "file-search", "version": "1.0.0", "description": "My CLI tool to
search files", "main": "index.js", "author": "Henrique Schreiner", "license": "ISC", }
{ "name": "file-search", "version": "1.0.0", "description": "My CLI tool to
search files", "author": "Henrique Schreiner", "license": "ISC", "preferGlobal": true, "bin": { "file-search": "index.js" } }
# Creating the Script
root@hmschreiner : ~/my-tool-folder $ vim index.js #!/usr/bin/env node --harmony 'use
strict'; console.log('This is the file-search script.');
# Installing the Script
root@hmschreiner : ~/my-tool-folder $ npm link - Install the script
on your system - Creates a symlink to your project so that you can run the project whilst working on it - No need to keep reinstalling it over and over again
root@hmschreiner : ~ $ file-search This is the file-search script.
# Processing Arguments
root@hmschreiner : ~/my-tool-folder $ vim index.js #!/usr/bin/env node --harmony 'use
strict'; console.log(process.argv);
root@hmschreiner : ~ $ file-search hello [ 'node', '/Users/hmschreiner/bin/file-search', 'hello'
]
root@hmschreiner : ~/my-tool-folder $ vim index.js #!/usr/bin/env node --harmony 'use
strict'; let inputArgs = process.argv.slice(2); let searchPattern = inputArgs[0];
# Searching for Files
root@hmschreiner : ~/my-tool-folder $ vim index.js #!/usr/bin/env node --harmony 'use
strict'; const exec = require('child_process').exec; let inputArgs = process.argv.slice(2); let searchPattern = inputArgs[0]; exec(`ls -a | grep ${searchPattern}`, (err, stdout, stderr) => { console.log(stdout); });
root@hmschreiner : ~/my-tool-folder $ file-search package package.json
# Next Steps
root@hmschreiner : ~/my-tool-folder $ npm publish - Ensure a good,
well written README file - Decide on an initial version number (e.g. 1.0.0) - If you’ve not registered on npm...
root@hmschreiner : ~/my-tool-folder $ npm adduser - Follow the prompts
to set up and authenticate yourself - Once published, users can then install your module
root@hmschreiner : ~ $ npm install --g file-search /usr/local/lib └─┬
[email protected]
...
# Thank You!