Let's get your first lesson going

This page will take you to all the steps necessary to create your first program and execute it.  For all other lessons, you can simply repeat these steps.  This page is the companion for Page 8 of the PodPi magazine edition #1.

Questions?  If you have questions and if something is not clear, send us a note using this form


Open your Terminal app

Open your Terminal app

10. Open your Terminal app

This will be the window you use to type the various commands to launch your editor and execute your program.  The commands you type in this window are actual commands sent to your computer only.  They are not the JavaScript program lines of code found in the lessons.  The JavaScript code needs to be saved into a file instead (see step 11).


Launch your editor

Launch your editor

11. Launch your editor

In order to execute your programs, you have to create a file, save it and then tell Node.JS to execute it.  First you need to launch the editor that you will use to write the program.  You can use any editor of your choice, but for this exercise let's use nano - it is simple to use.  In your Terminal window, simply type:

nano led.js <enter>

"nano" will call the nano editor and pass it the name of your program, in this case "led.js".  The <enter> is simply the "enter" or "return" key on your keyboard.

To create different programs, simply name your file with a different name.  For example, rgb.js or light_sensing.js.


Write your code in the editor

Write your code in the editor

12. Write your code

Now that you have the editor open, write the JavaScript code that you find on the lessons, or code that you are experimenting with.

Make sure to respect the format of the code (spacing, upper/lower case, notations, etc.).  The code will fail to execute if you have any typos, wrong characters, etc.

You can find the first lesson on page 11 of the magazine edition #1.  Simply type the code located in the middle of the page.


Save your file

Save your file

13. Save your file

Congratulations!  You have written your code, now it is time to save your file to make sure your computer retains it as you exit your editor.

Simply press Control+X, then reply with Y and press Enter.


Execute your program

Execute your program

14. Execute your program

This is the exciting moment you've been working hard to achieve.  Executing your program and discovering what it does!

To execute your program, simply type the following command:

node led.js <enter>

"node" is the command that launches your local JavaScript run-time.  "led.js" is the name of the program you want to execute.  If you have renamed your program or have a different program you want to execute, simply change the name led.js to your program name and press the "enter" or "return" key.


15. Stop the program

Now it's time to stop your program and make changes to it.  Simply press "CTRL-C" twice.  This should return you to the command prompt and be ready for the next command.

You can now go to your next lesson and repeat the steps from 11 onward.

and remember to have fun!