Skip to content
Browse files

Finished the npm installation and configuration segments

  • Loading branch information...
1 parent 23e3612 commit fb9e50c9b11cc87d083cf9bcbe62b67b51acadc9 @croach committed Jul 2, 2012
Showing with 35 additions and 5 deletions.
  1. +35 −5 02.md
View
40 02.md
@@ -69,15 +69,45 @@ Well, that should be enough to get you started with nvm. The app is fairly simpl
## Node's Package Manager (NPM)
-If you thought the install for nvm was easy, wait until you see the install for npm...
+NPM is one tool that I think makes node worth using even if you're not completely sold on all of node's other strengths. I consider it to be the new standard that all package management systems should strive to live up to. I hope by the end of this screencast you'll agree with me, and that you'll have some idea as to just how powerful and easy to use NPM is, and, in a future screencast, I hope to cover it a bit further by showing off just how easy it is to create and distribute your own packages. But that's enough praise for the program, let's go ahead and get it installed and start playing around with it a bit.
-Did you get all that? No, don't worry, I didn't accidentally edit out the npm install or anything it's just that npm comes already installed with all of the latest version of node. Anything after the 0.4 series should already come with npm installed and I believe, correct me in the comments if I'm wrong, all versions from v0.4.3 and up have npm already installed. So, essentially your done. However, there is one piece missing to the default install of npm... the docs!
+### Installation
+
+Speaking of installing NPM, if you thought the install for nvm was easy, wait until you see the install for npm...
+
+Did you get all that? No? Don't worry, I didn't accidentally edit out the npm install or anything it's just that npm comes already installed with all of the latest versions of node. I believe---and correct in the comments, if I'm wrong---anything after the 0.4 series (specifically, v0.4.3) should already come with npm installed. So, essentially---your done. That said, I did run into a few minor problems accessing the documentation for my install of NPM and I'll cover how I fixed the issue, just in case any of you run into the same problem.
+
+### Documentation
+
+Now npm loves Unix, and it shows in its documentation. All of the docs for npm are man pages and even the website docs are just an HTML version of the man pages. So it stands to reason that you'd probably want to have this very valuable bit of information right at your fingertips. However, if you try executing `man npm` from the command line, you may get back something to the tune of "No manual entry for npm". Now, you could also access the same man pages through the `npm help` command like so (run `npm help npm`), but if you're like me, you like everything to work as you'd expect it to and being able to call the `man` command to see a man page is just something that's gotta work, right?
+
+Well, the fix that I've found for this is really quite easy and it's simply to upgrade your version of npm. Doing so will put a smile on the face of any lisp programmers since you'll actually be using npm to update npm---how very meta. Just type `npm update -g npm` at the command line to fetch and install the latest version of npm for the current version of node that you are using.
+
+Once the update is finished, you should be able to type `man npm` and get the main man page for the npm program. Now you can also find help for each of the commands that npm supports by typing either `man npm-<command_name>` or `npm help <command_name>`. Both should work and both should show you the same information, namely the man page for the given command.
+
+### Configuration
+
+Now that we have the latest version of npm installed on our system, let's play around a bit and see what all it has to offer. npm is extremely configurable and has tons of cool features for you to explore. To start off, let's take a look at changing the default format for the documentation.
+
+We just saw how we can view the documentation for npm via man pages, but what if you don't happen to be a fan of reading docs from the command line? Perhaps you'd like your documentation to be in the form of a web page? If so, there's a configuration setting just for you.
+
+We'll be using npm's `config` command to change the 'viewer' setting, but before we do, let's take a look at what the `config` command has to offer us by typing `npm help config` and checking out the Synopsis section of its documentation. We can see here that we have four different options available to us---namely get, set, list, and delete---and we'll be putting all of them to use in this segment. At the bottom of this documentation, you'll find descriptions of each of the available settings that we can change, so let's find the description for the "viewer" setting before we exit back out ot the command line.
+
+You can search for text in a man page by hitting the forward slash and then typing in the text that you're looking for, so let's type in `/viewer` and press enter. Here we can see that we have the option of setting the "viewer" configuration variable to be either "man", for man pages, or "browser", for HTML. Now that we know what are options are, let's exit back out and update the configuration.
+
+Before we change the configuration though, let's first take a look at the current value of the 'viewer' variable and verify that it is in fact set to "man". Type `npm config get viewer` and press return and you should see that the current value is indeed set to "man".
+
+Now let's change the "viewer" variable to "browser" by typing `npm config set viewer browser` and pressing return. In true Unix fashion, if everything went well, we won't get any output, but just to make sure everything worked properly, go ahead and type `npm get viewer` and hit return to verify that "viewer" was properly changed (by the way, according to the man page, you can drop the config when doing a get or a set, which is why I was just able to get away with typing `npm get viewer`).
+
+If "browser" was returned, you've successfully updated the "viewer" configuration setting and you're ready to start viewing the npm documentation in glorious technicolor, er, um, HTML. Go ahead and give it a try now by typing `npm help npm` into the command line. Hopefully, your default browser opened up with the documentation for npm in it. If not, you may need to install Chrome for this feature to work.
+
+To revert the configuration, we can simply delete it. We can see why this is true by taking a look at our current npm configuration settings with the `list` command (or you can use `ls` for short). There are two things to notice from the output of the `list` command. First, you can see that all the `config` command does is manage a user-specific configuration file called `.npmrc` found in your home directory. So you could simply bypass the command and set everything there by hand. The second thing to notice is that the `list` command is only showing us the settings that we've updated. If we want to view all of the settings---including the default settings---we'll need to add the long, or `-l`, option to the command. Go ahead and try that now by typing `npm config ls -l` and you should see a whole slew of settings fly by.
-npm loves Unix and it shows in its documentation. All of the docs for npm are man pages and even the website docs are just an HTML version of the man page documentation, so it stands to reason that you'd probably want to have this very valuable bit of information on your local system. However, if you do a `man npm` you'll get back something to the tune "No manual entry for npm". So, how do we get the docs installed? Well the easiest way that I've found is simply to upgrade our version of npm. To do so we'll use npm, so just type `npm update -g npm` at the command line. Once the update is finished, you should be able to type `man npm` and get the main man page for the npm program. Now typing `npm help <command>` will also bring up the man page for each of the commands that npm supports.
+Given that all we're doing by changing the "viewer" setting is essentially overriding the default value, it would stand to reason that we can simply delete the setting from our config file and it should revert back to the default. Let's do that now by typing `npm config delete viewer` and press return. A quick check with `npm get viewer` confirms that the configuration setting has been reverted and running `npm help npm` confirms it further by opening up the documentation in the terminal rather than the browser.
-### Configuration and documentation
+One final note, if you'd prefer to keep the default settings, but you still want to view the docs in the browser from time to time, npm let's you do so by setting a configuration variable via a command line option. Any configuration setting can be set via the `--key value` command line option. Let's try it real quick by opening up our main npm documentation again in the browser by typing `npm help npm --viewer browser`, and it should open up a browser window again containing the npm docs.
-Now that we've got the latest version of npm installed on our system, let's play around a bit and see what all it has to offer. npm is extremely configurable and has tons of cool features that you can play with. Let's get started by changing the default format for the documentation. We just saw how you can view the documentation for npm via man pages, but what if you don't happen to be a fan of reading docs from the command line? Perhaps you'd like your documentation to be in the form of a web page? If so, there's a configuration setting just for you. Let's start by taking a look at what the current setting is. Type `npm config get viewer` to see what the current medium for documentation viewing is. You should see 'man' get printed to the screen. Let's change that now to be the browser by typing `npm config set viewer browser` and confirm the change by typing `npm config get viewer` again. If 'browser' is now printed out, you've successfully updated the viewer configuration setting and you're ready to start viewing the npm documentation in beautiful HTML. Go ahead and give it a try now by typing `npm help npm` into the command line. Hopefully, your default browser opened up if you're running OS X, otherwise, I believe you need to Chrome installed for this feature to work. To revert the configuration setting back to it's default, just delete it with `npm config delete viewer`. A quick check with `npm get config viewer` proves that the configuration setting has been reverted and running `npm help npm` further proves it by opening the documentation in the terminal. On a final note, if you want to keep the default settings, but you still want to view the docs in the browser from time to time, npm let's you do so by setting a configuration key via a command line option. Any configuration setting can be set via the `--key value` command line option. Let's try it real quick by opening up our main npm documentation in the browser again by typing `npm --viewer browser help npm`. The main reason that I'm running through all the different ways to view the docs is that npm is extremely featureful and very powerful and it's worth it to get lost in the docs for a few hours just to get an idea of what all it has to offer. So after we finish up with this tutorial, you should do yourself a favor and pop open the main help page and just read through and try out stuff, you won't regret it.
+The main reason that I'm running through all the different ways to view the docs is that npm is extremely featureful and very powerful and it's worth it to get lost in the docs for a few hours just to get an idea of what all it has to offer. So after we finish up with this tutorial, you should do yourself a favor and pop open the main help page and just read through and try out stuff, you won't regret it.
### Tab completion

0 comments on commit fb9e50c

Please sign in to comment.
Something went wrong with that request. Please try again.