Alt.Tekpub - Installing and Setting Up Node
- javascript
- alt.tekpub
- nodejs
- Wednesday, February 22, 2012
The data has been rolled into MongoDB - at least the first round - and now I need to get the API up and tested.
Hello Node
Installing NodeJS is pretty simple these days. Understanding what's going on takes just a bit more effort. My goal today is to get NodeJS installed and then lay in the Express framework on top of it (think Sinatra for Node).
The first part is easy: head over to NodeJS.org and download your installer flavor. If you're on a Mac you could use Homebrew but I find the installer works great. It also installs the Node Package Manager (NPM) which you can think of as Rubygems (or Nuget if you're a .NETter).
The bundling of NPM is a big deal :). It used to be that Node and NPM might get out of sync, causing all kinds of headaches - nowadays they tend to be a bit more compatible.
Express
The first package we want to install is Express. This is a Sinatra-style, bare-boned web framework that will help us keep our routes clean and give us a tad bit of structure. If we want more - there's Railway but I don't need that just yet.
So, to install Express I simply write:
1 | |
1 | |
You should have seen a few lines of code go by. If you didn't and received an error, it's likely you forgot the -g flag when you installed Express.
Let's jump into our new directory and install all of the modules we'll need to work with Express. These aren't installed by default - in the same way that < Rails 3.1 didn't install the gems for your Rails site by default - so we need to tell npm to drop em in:
1 | |
1 | |
Now, open a browser and head to http://localhost:3000. Whoop!
-
- Tweet
-