$30 off During Our Annual Pro Sale. View Details »
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
63
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
81
Como convencer seu time a mudar de tecnologia
hmschreiner
2
470
Javascript with Classes
hmschreiner
0
61
Other Decks in Programming
See All in Programming
社内オペレーション改善のためのTypeScript / TSKaigi Hokuriku 2025
dachi023
1
570
配送計画の均等化機能を提供する取り組みについて(⽩⾦鉱業 Meetup Vol.21@六本⽊(数理最適化編))
izu_nori
0
150
俺流レスポンシブコーディング 2025
tak_dcxi
14
8.5k
ハイパーメディア駆動アプリケーションとIslandアーキテクチャ: htmxによるWebアプリケーション開発と動的UIの局所的適用
nowaki28
0
400
AIコーディングエージェント(NotebookLM)
kondai24
0
170
MAP, Jigsaw, Code Golf 振り返り会 by 関東Kaggler会|Jigsaw 15th Solution
hasibirok0
0
230
チームをチームにするEM
hitode909
0
300
組み合わせ爆発にのまれない - 責務分割 x テスト
halhorn
1
140
【Streamlit x Snowflake】データ基盤からアプリ開発・AI活用まで、すべてをSnowflake内で実現
ayumu_yamaguchi
1
120
堅牢なフロントエンドテスト基盤を構築するために行った取り組み
shogo4131
8
2.3k
AIエージェントを活かすPM術 AI駆動開発の現場から
gyuta
0
370
複数人でのCLI/Infrastructure as Codeの暮らしを良くする
shmokmt
5
2.2k
Featured
See All Featured
Six Lessons from altMBA
skipperchong
29
4.1k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
970
Optimizing for Happiness
mojombo
379
70k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.5k
GitHub's CSS Performance
jonrohan
1032
470k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Done Done
chrislema
186
16k
Testing 201, or: Great Expectations
jmmastey
46
7.8k
A Modern Web Designer's Workflow
chriscoyier
698
190k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
How GitHub (no longer) Works
holman
316
140k
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!