More about the terminal
In the last lesson, we used the terminal commands cd
and node
.
Let's look at what these do in detail.
The terminal works just like the Finder on a Mac, or Explorer on Windows. It lets you move into and out of folders, and run files in the current folder.
Go home
When we open the terminal for the first time, it will be "in" a particular folder—the home folder. For Codeenvy, this folder is called /projects
.
From the previous lesson, your terminal should be in a subfolder called my-app
or similar. We can leave this folder, and go back to the home folder by typing:
cd ~
Whatever folder your terminal is in, typing this command will send it back to the home folder: /projects
.
Change directory
cd
means change directory. We can type cd
, followed by the name of a subfolder, to go inside it.
We can also use characters like ~
as shortcuts to go back to the home folder.
In more complicated situations, we might have many subfolders inside each other, and may need to jump "out" of one folder into its parent.
Let's pretend we have a folder /parent
, which contains a subfolder /child
, which itself contains the folder /grandchild
.
If the home folder is /parent
, we can navigate in by typing cd child
and then cd grandchild
.
From /grandchild
, we can jump back out to /child
by typing:
cd ..
List files
We can list all the files in the terminal's current folder by typing:
ls
Run a program
We can use Node to run a Javascript program from the terminal.
We just need to type the word node
followed by the name of the file we want to run.
Node only runs Javascript programs, so you don't need to include the .js
file extension. node hello
is fine.
The terminal must be in the right folder first. If you make this command from a folder that doesn't contain the file you want to run, you'll get an error.
Part of Web servers
- Create your serverP
- Create your appP
- Node and the terminalP
- More about the terminalP
- Web frameworksP
- Using ExpressP
- Serving static files
- Views and templates
- Routing
- Real data
- Includes
- Get confident with Express
- Build your app in ExpressP