Here are some examples of common patterns in Javascript.
Run examples/commandLineArgs.js from the command line and read the code to get an overview of how command line arguments work.
When we run a program like:
node hello.js one two three
our program in hello.js
can get access to an array that looks like
['one', 'two', 'three']
These are called "command line arguments".
Run examples/add.js from the command line to see how it works. This is a "fully-featured" command line program that adds two numbers.
It contains proper error handling and useful help messages. It's heavily commented.
In JavaScript, we use Math.random to generate random numbers.
Run examples/random.js from the command line and read the code for an overview of common patterns involving random numbers.
Run examples/readFile.js from the command line and read the code to see examples of how to read from a file.
Run examples/keyboardInput.js from the command line and read the code to see examples of interactive keyboard input.
We're using the readline-sync module.
You'll need to run the following command inside the examples-javascript
directory to install readline-sync
:
npm install
Hidden Input
Run examples/password.js from the command line and read the code to see examples of how to hide user inputs.
We're using the readline-sync module.
You'll need to run the following command inside the examples-javascript
directory to install readline-sync
:
npm install