Express.Js – Survey Form

Express.JS:

Turns out that creating on server on Express.js is significantly easier than in Node.js!

I went through the practice material and starting the first assignment to create a survey form which I figured out relatively easy, which surprised me a little.

The assignment was to have the user fill out a survey form below:

Screen Shot 2016-05-08 at 7.51.09 PM

This information should then be saved in app.post, using a callback function to save the data into an array that will later be used to display the results on a different page called /result.

Having the data appear on a separate page was fairly simple and the syntax to have the data display the results was similar to how we did in PHP which was to access the key (in this case: users) and the name of the field to be displayed such as name, location etc.

Screen Shot 2016-05-08 at 7.55.40 PM (2)

We were to have a button ‘Go Back’ to go back to the main page where the form was originally displayed. Initially, I had a input type submit with a value of “Go Back” wrapped into a form which would send a get request to get the page of index (the original page). I was having trouble with this though because the url had a ? mark next to the localhost like this: localhost:8000/? which I found out is because it’s expecting data from get but since it receives nothing, it returns a question mark. The instructor told me a better way which is to create a button and wrap it in a link with a href pointing to the home page. Now, it works like a charm.

My server.js file below:

Screen Shot 2016-05-08 at 7.52.58 PM (2)