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
57
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
76
Como convencer seu time a mudar de tecnologia
hmschreiner
2
460
Javascript with Classes
hmschreiner
0
48
Other Decks in Programming
See All in Programming
Elm 0.19.0 Changes
bkuhlmann
0
490
Compose-View Interop in Practice (mDevCamp 2024)
stewemetal
0
160
Fragment Composition of GraphQL
quramy
13
1.4k
CA.swift19 恋するAIアプリ開発の裏側
oskmr
0
380
Goのエラースタックトレースの歴史と今後
sonatard
10
1.7k
Hanami and htmx
bkuhlmann
0
220
Introducing Kotlin Multiplatform in an existing mobile app - Workshop Edition | AndroidMakers Paris
prof18
0
140
PHPはいつから死んでいるかの調査
chiroruxx
2
410
新宿ダンジョンを可視化してみた
satoshi7190
3
340
2 週間で Twitter Bot を作ってみた
contour_gara
0
750
見た目から始める生産性向上
ikumatadokoro
9
1.3k
OpenAPIを中心に考えるAPI開発入門 / Introduction to API Development with a Focus on OpenAPI
seike460
PRO
2
170
Featured
See All Featured
How STYLIGHT went responsive
nonsquared
92
4.8k
Git: the NoSQL Database
bkeepers
PRO
423
63k
GitHub's CSS Performance
jonrohan
1025
450k
What’s in a name? Adding method to the madness
productmarketing
PRO
17
2.7k
What the flash - Photography Introduction
edds
64
11k
Building an army of robots
kneath
300
41k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
222
21k
Mobile First: as difficult as doing things right
swwweet
217
8.6k
Atom: Resistance is Futile
akmur
260
25k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
26
2.3k
What's in a price? How to price your products and services
michaelherold
238
11k
Automating Front-end Workflow
addyosmani
1357
200k
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!