BETAThis is a new service – your feedback will help us to improve it.

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.

Test this out by returning from your /my-app folder to /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 ..
Create a subfolder inside your /my-app folder and try this out.

List files

We can list all the files in the terminal's current folder by typing:

ls
Try this out on your /my-app folder.

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.

Lessons last updated 12th July 2019. You can improve this lesson on Github.
Part of Web servers
  1. Create your serverP
  2. Create your appP
  3. Node and the terminalP
  4. More about the terminalP
  5. Web frameworksP
  6. Using ExpressP
  7. Serving static files
  8. Views and templates
  9. Routing
  10. Real data
  11. Includes
  12. Get confident with Express
  13. Build your app in ExpressP