-
Book Overview & Buying
-
Table Of Contents
Node Cookbook
By :
If we want to be able to receive POST data, we have to instruct our server on how to accept and handle a POST request. In PHP we could access our POST values seamlessly with $_POST['fieldname'], because it would block until an array value was filled. By contrast, Node provides low-level interaction with the flow of HTTP data allowing us to interface with the incoming message body as a stream, leaving it entirely up to the developer to turn that stream into usable data.
Let's create a server.js file ready for our code, and an HTML file called form.html, containing the following code:
<form method=post> <input type=text name=userinput1><br> <input type=text name=userinput2><br> <input type=submit> </form>
For our purposes, we'll place form.html in the same folder as server.js, though this is not generally a recommended practice. Usually, we should place our public code in a separate folder from our server code....