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:
- Start VS Code on your development computer. You can go to the Window's Start menu Search Box, and type:
Visual Studio Code
File > Open Folder, and create a new folder for your development exercises.
VS code will use this folder structure to manage work spaces.
File > New Fileand then type
<cntrl>+sto save this new file with the filename:
- Edit the file to include the code shown in this screenshot:
- Save the changes by typing:
- Use the integrated command line terminal in VS Code by selecting
View > Integrated Terminal
- At the Terminal prompt, navigate to the folder you created in step 2 (above), and type:
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.
- 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.
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.
- 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. ).
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.