NodeJS

Welcome to Node.js: Part 4 – Downloading and Installing Express and MongoDB

July 8, 2014

The further I dig into this, the more tutorials I find. Some have more information than others, and others are better organized, but they all seem to solve different pieces of my particular puzzle. One that seems to come particularly close to our MEAN stack endeavor is the helpfully titled guide from Christopher Buecheler. He doesn’t mention AngularJS and uses Jade instead, which actually seems to be a “natural” component included with Express, but we can figure out the difference later.

Take a left at the magic beanstalk, retrieve the mage's staff of apt-get, head straight to the lava pit and download MongoDB...

Take a left at the magic beanstalk, retrieve the mage’s staff of apt-get, head straight to the lava pit and download MongoDB…

If you read Part 1, I recommended the Modulus guide (written by Brandon Cannaday) for downloading and installing Node.js. I liked Buecheler’s “hello world” opener a little more, but that’s my (extremely) novice opinion. The two tutorials achieve different operations, though, and I think running through both is in your best interest if you’re starting at the same relative knowledge base that I have.

Obviously, I don’t want to simply repeat what others have written (many, many, many times over). But I do want to trace a path toward a functional understanding of our MEAN stack. I’ve worked through all of Cannaday’s “absolute beginner’s” guide, and the first two parts in Buecheler’s guide without any trouble. For all our sakes, I’ll assume you’ve at least read that far and I won’t repeat those steps. We’ve already covered installing Node.js, and installing Express is as simple as running two commands from your terminal:

npm install -g express
npm install -g express-generator

FrustrationI ran into confusion with MongoDB. Buecheler’s post is not *nix-centric, and I had a little trouble moving from the instructions on the MongoDB website (to download it onto my Ubuntu 12.04 virtual machine) to Buecheler’s instructions in Part 3. First, it took me a bit to track down where Ubuntu put everything from the MongoDB installation instructions. So when I tried to, “copy the files in the bin folder within your temp directory to wherever you want Mongo to live,” I just left the mysterious Mongo creature lie where it had been put—which was /var/lib/mongodb.

Computer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter.
-Eric S. Raymond

And then, when I tried to connect from that directory to the “data” folder Buecheler tells us to create, it took me another hour (or four) of charming self-control (obnoxious whining) to figure out I needed to translate from Microsoft to *nix. (Have I mentioned I am a beginner? I’m reminded of the Eric Raymond quote…) Hopefully, I’ll save someone else this trouble. I even messaged the eminent Mr. Buecheler in my befuddlement, and he courteously explained that, having followed the installation instructions on the MongoDB website, I had already arrived with a working instance of the db.

As it turned out, if you’re using Ubuntu (or another *nix, I’d think) you can pretty much skip Steps 1 & 2 of Part 3 in Buecheler’s guide after following the Mongo website instructions. Seriously, I wish I had more to show for the amount of time I spent on this particular hurdle, but here we are. I finished Buecheler’s wonderful tutorial a little older, a little wiser. A little less hair. I have to say, it was ridiculously, disproportionately satisfying to see the browser read and write to a wee little database.

This is the headlining image from restfuldevelopment.net. I'm as confused by REST as I am by this picture.

This is the headlining image from restfuldevelopment.net. I’m as confused by REST as I am by this picture.

So far, we’ve got Node.js, MongoDB, and Express, and we’ll loop back around for AngularJS later. Before we go there, I was hoping to suss out yet another acronym that pops up all over the place—REpresentational State Transfer, known as REST. I’ve done the Wikipedia search, checked multiple Google responses, and a Stack Exchange question or two, and I still have a really hard time picturing what exactly REST is. There is a helpful video here, but I was honestly still lost by the end of it. It just so happens that Mr. Buecheler tackles this enigma as well at the beginning of his very next tutorial, which follows immediately on the heels of the first. It’s not an in depth dissection, but it does a better job than most of painting the general picture.

I know we haven’t actually built anything, yet, but hopefully I’ve helped you along your own learning curve as I serve the role of evolution’s whipping boy—that goofy, odd-looking critter from whom all the other creatures at the watering hole learn what not to do in the programming wilds. I’ve had to rebuild my virtual machine probably twelve times over the course of the last few weeks as I keep screwing around with all of this stuff. But for all that, this is a lot of fun, and I’m glad to see the pieces coming together. In the next post, I’ll have a new batch of problems (and hopefully answers) for you as we work toward understanding Node.js.

Nate Aeilts

Nate Aeilts is currently enrolled in an internship program at MPA. Nate is a student at Taylor University, and enjoys learning about programming and new tech tools. He likes dogs and chocolate, though he acknowledges they do not mix well.

Post your comment