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
10. Open a Command Prompt window.
Find more information about the Command Prompt on the Microsoft help.
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 Notepad - it is simple to use. In your Command Prompt window, simply type:
notepad led.js <enter>
"nodepad" will call the 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.
12. Write your code
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.
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.
You do not have to close your editor. Simply click Save (or press CTRL-S) and your file will be saved. Next, go to the command prompt to execute it.
If you want to create a different version, you can simply click "Save as...", then give it a different name with the .js extension. You may need to select "All file types" in the drop-down below the name field.
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>
15. Stop the program
Now it's time to stop your program and make changes to it. Simply press "CTRL-C" twice. You may also have to press the "enter" key afterward (only on some version of Windows). 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.