Create Your Node.js Hello World

Every development framework and programming language starts with a Hello World example.   The Node.js documentation (https://nodejs.org/download/release/v8.15.0/docs/api/synopsis.html) provides a node.js version of the Hello World example, which is to create a server on the local host that responds "Hello World" to a basic http request to port 3000.  

We begin by using VS Code:

  1. Start VS Code on your development computer.  You can go to the Window's Start menu Search Box, and type:  Visual Studio Code  

  2. Select File > Open Folder, and create a new folder for your development exercises. 
    VS code will use this folder structure to manage work spaces.

  3. Select File > New File and then type <cntrl>+s to save this new file with the filename: hello.js   

  4. Edit the file to include the code shown in this screenshot:




  5. Save the changes by typing:  <cntrl>+s  

  6. Use the integrated command line terminal in VS Code by selecting View > Integrated Terminal  

  7. At the Terminal prompt, navigate to the folder you created in step 2 (above), and type:  node hello.js  
    This command should respond with "Hello World", as show below.




    NEXT:  Run This Application Using the VS Code Debugger
    The next step is to run this application using the debugger integrated in VS Code.

  8. In VS Code, set a break point by clicking to the left of the first line of code in hello.js.   
    A red dot appears to the left of the line number to indicate the break point presence.




  9. In the VS Code activity bar, click the Debug icon () to shift from code editing to debugging. 
    The current active source file should be targeted.  If No Config appears next to the green triangle button (the Start icon ), then the current active will be targeted to debug. 


  10. Click the  icon next to DEBUG in the navigation pane to start debugging.   

      

  11. To drive your debug activities, use the code stepping tools (). 
    Notice that as the application steps past the second line of code (the console.log method), the "Hello World" message is sent to the Debug console and appears below the Debugger listening line, as shown in the figure below. 


Next Step

Now that you have created your Node.js Hello World, you can move on to the next step in this tutorial:  Create Your MQTT Hello World.