Lesson 1: Getting started with Node.js CHAPTER 8 359
The response has a writeHead method to write headers. There is also a write method to
write HTML to the browser. Finally, you can use the end method to send the last bit of HTML
to the browser and close the connection.
In the command prompt window, run the application by executing the following
command.
node appAfter the application is running, open the browser and enter the following URL.
http://localhost:8080/HelloForm.htmlYou see the webpage, as shown in Figure 8-9.FIGURE 8-9 he HelloForm.html webpage retrievedTEntering a name in the text box and clicking the Submit button presents the form data to
the server. The QueryString is processed, and the result is displayed, as shown in Figure 8-10.FIGURE 8-10 he result displayedTIn this example, when you click the Submit button, the URL changes to the following.
http://localhost:8080/SubmitHello?userName=GlennThe routing in the app.js file matches the resource of SubmitHello and then executes the
code associated with the resource. In the code, userName is retrieved from the QueryString.