Server-side (file is named server)
This code is invoked with: node server
Once it is invokec, call the page with http://example.com:1337/form.html
The client side code is in the static directory. There is a simple form:
This code fires when a button with the id of "go" is clicked. It gets the values of the inputs, creates an object and sends it to the server.
Notes for those who are patient or really desperate.
- app.post doesn't make a post request, it accepts one with the URL in the first parameter. In this case, it will accept a post response for / on port 1337.
- Express is a nice framework for node. Use it.
- You need to use npm to install both Express and body-parser.
- bodyParser parses the request body from JSON. It can handle other formats, too
- Be sure to put the static files in the static directory, or update the express.static call accordingly.
- Note that there is no charset on the content type header sent to node. Node is looking for "application/json"
- The validation is really limited, the goal of this code is to show how to set up the form.
- You may have to update your firewall settings to allow access to port 1337. If you are on an Amazon instance, use their web console.
- When all else fails, read the documentation.