from WarGames, (1983)
Computers used to not have screens! They were connected to devices like this:
The Terminal app is a direct descendant of a TeleType printer or TTY.
When you type into the console and hit Enter you are pretending to type a line onto a TTY; the scrolling terminal is like a roll of printer paper.
See this twitter thread for more history and TTY pix.
picture of Teletype Corporation ASR-33 on display at the Computer History Museum by ArnoldReinhold [CC BY-SA 3.0] via Wikimedia
to open your Terminal:
{bash::bash}
C:\Users\yourname
cmd.exe
or PowerShell
) -- but beware, the commands are slightly different than in bashImportant: make your terminal as tall as possible and don't overlap windows
$
or >
symbolnode
-- that's you commanding the computer to launch node
>
prompt1 + 1
2
An "engine" is a type of program that either executes or empowers other programs.
NodeJS (aka node
) is an engine that runs JavaScript programs -- either from files, or interactively from the command line.
WARNING: Before you start typing, look at the prompt!
Davids-Macbook-Pro:~ David$
(Mac)david@davidspc:~$
(Ubuntu Linux)C:\Users\david>
(Windows)>
From inside node
, if you want to get back to the shell...
.exit
and Enter
From now on, whenever you see text in the code font
, try typing it into the terminal and see what happens! For example:
'pod' + 'cast'
If that doesn't print 'podcast'
, look at the prompt; you may be inside your shell instead of inside node.
code
directory inside your home directorycode
for each lesson or projectWARNING: On some windows systems, Command Prompt will open to
C:\Windows\System32
. You can get back to your home directory by typingcd %HOME%
when you type ls
("list") it shows the contents of the current directory
dir
insteadif you type ls -al
("list all long") it also shows hidden files and extra info like the modification date
dir /A:SH
insteadmkdir
("make directory") it creates a new subdirectory inside the current directorymkdir code
cd
("change dir") moves you into a different directorycd code
would move you into a subdirectory named code
cd
all on its own and press the return key. This will send you back to your home directory.
pwd
("print working dir") -- shows the name of the current directoryls
("list") -- shows the contents of the current directorymkdir
("make dir") -- creates a new subdirectory inside the current directorycd
("change dir") -- move into a different directoryThese apply to Mac / Unix / Linux / bash
cd
("change dir") -- With no directory, it lists the current directory. Otherwise, it changes to the specified directorydir
("directory") -- shows the contents of the current directorymkdir
("make dir") -- creates a new subdirectory inside the current directoryThese apply to Windows / DOS / PowerShell
mkdir code
cd code
pwd
cd
ls
(and note that it's empty)
dir
node
and then the name of the source file, like this:$ node hello.js
Hello, World!
code
subdirectory using pwd
or cd
code .
("code dot")hello.js
using the File > New menuInside this file, put the following source code:
console.log("Hello, World!");
Save the file
Switch back to the terminal (using Alt-Tab or Cmd-Tab or clicking)
(If you are using VS Code, you can click Terminal → New Terminal for the built-in terminal panel)
Run this file using node hello.js
What happens? Is this what you expected?
code
directory, create a file named countdown.js
Inside this file, put the following source code:
let count = 10;
while (count > 0) {
console.log(count + '...');
count = count - 1;
}
console.log('Blastoff!');
Save the file
In your terminal, run node countdown.js
Consider this a sneak peek; we will cover all of these concepts in later lessons
These work in bash
:
Also:
node h
Tab will emit node hello.js
)(image source: Clément Chastagnol)
Want to learn enough command line to be dangerous? Check out https://www.learnenough.com/command-line-tutorial by Michael Hartl (founder of Tau Day and all around solid geek).
Want to be a command-line hacker like in War Games?
Play this game: http://overthewire.org/wargames/bandit/ where you use your real command line ssh
tool to connect to sandboxed hosts and infiltrate them.
Want to learn the history of software user interfaces and operating systems? Read In The Beginning Was The Command Line by Neal Stephenson
/