Scripting Tips

Javascript

Start hello.js file off with appropriate shebang: #!/usr/bin/env node

Do something cool:

#!/usr/bin/env node
console.log("Hello, World!");

Change the file permissions to executable: chmod u+x hello.js

Execute from the terminal: ./hello.js

Advanced

ShellJS: Portable Unix shell commands for Node.js

ShellJS is a portable (Windows/Linux/OS X) implementation of Unix shell commands on top of the Node.js API. You can use it to eliminate your shell script's dependency on Unix while still keeping its familiar and powerful commands. You can also install it globally so you can run it from outside Node projects - say goodbye to those gnarly Bash scripts!

Commander: node.js command-line interfaces made easy

A good example is Gitbook's cli script (in node_modules/.bin of this repo).

Tutorial

Build a full-on CLI in node: https://www.sitepoint.com/javascript-command-line-interface-cli-node-js/

  • chalk — colorizes the output
  • clear — clears the terminal screen
  • clui — draws command-line tables, gauges and spinners
  • figlet — creates ASCII art from text
  • inquirer — creates interactive command-line user interface
  • minimist — parses argument options
  • configstore — easily loads and saves config without you having to think about where and how.
  • simple-git — a tool for running Git commands in a Node.js application
  • touch — a tool for implementating the Unix touch command.

results matching ""

    No results matching ""