If you must save state, save it on the client side via cookies or other methods.
A front-end framework like Angular (outside the scope of this tutorial, but stay tuned!
If you'd like to store them elsewhere, that's absolutely fine …just know that you need to have the directory ready before running Mongo DB.The first thing we'll want to do is update Express and the Express scaffolding generator globally, like this: As you'll remember from this last tutorial, this is going to auto-generate a website skeleton in a new directory called nodetest2.Watch as it does its thing, and when it's done, open the newly created file (in the newly created nodetest2 folder) in your text editor of choice, and change it so it looks like this: As usual, these versions are up to date as of the "last update" box at the top, and are proven to work with this tutorial. Note that we're adding the Mongo DB and Monk packages so that we can access and control our database.Onward to – this is the only HTML file we'll need for the rest of our webapp.
We're going to put quite a lot of stuff onto this page.
That's it; we're going to prepopulate the database later in this tutorial, so we're done with setup for now. One final note: this article uses four-space indentation for everything because that's fairly popular in the Java Script community. I know this is a big debate, but honestly given how fast and easy it is to convert spaces to tabs and back again with any decent editor, I don't really see the issue.
Unless your team has a standard everyone's agreed to, you should work with what you want.
That's a great start, and if you're unfamiliar with those technologies, now would be an excellent time to go through the tutorial, because we're about to delve deeper. or rolling your eyes and going, “dude, I already know that stuff”? Let's add some new tools to our toolbox, and create a simple little app that works without a single page refresh. Let's try to put the concepts of REST in plain English.
You're going to need to know how to get a webserver running with Express, and how to use and to communicate with both the server and the database. Here are the goals: Basically, in the first tutorial, we built a simple front-end app atop the Router/View back-end. To do that, we're going to borrow four basic design principles from IBM's developer Works website, and explain what they mean. To update or change data, you use PUT (not used in this tutorial). So for example, this once-common approach is not a good one:
It's all covered in that original tutorial, and if you're a developer who's familiar with Java Script, it's not hard. In this tutorial, we're going to eliminate the need for page refreshing or visiting separate URIs entirely. But before we start building, let's get some REST … Use HTTP Methods Explicitly This one's pretty straightforward. newuser=bob That's an HTTP GET pretending to be a POST.