Skip to content
Browse files

Finished the script for Part 02

  • Loading branch information...
1 parent a6b1773 commit 86c59eb4e835bb2eb9138ed03441880a814b9b66 @croach committed Jul 22, 2012
Showing with 11 additions and 5 deletions.
  1. +11 −5 02.md
View
16 02.md
@@ -189,9 +189,13 @@ Well, with just a little code added to our .bashrc file we can create something
#### Virtual Environments
-Before we add the bash functions that will create our virtual environments, I want you to understand just what it is that these functions will be doing. So, let's first take another look in the local node modules directory, this time with the `-a` option. Notice a hidden file in there that we didn't see before called `.bin`. If you take a look inside of there, you'll see a symbolic link that points right to the express command in the locally installed package. This `.bin` folder is where npm links all of the executables that each package provides. So, if we can just get that folder added to our PATH environment variable whenever we `cd` into a node application's directory, we would gain access to each package's command line programs without the need to install them globally and I've created a few bash functions to do just that.
+Before we add the bash functions that will create our virtual environments, I want you to understand just what it is that these functions will be doing. So, let's first take another look in the local node modules directory, this time with the `-a` option.
-I'm not going to go over what the functions do here---if you're trully intersted, just ask in the comments and I'll post some notes on what the code does---but, for now, let's just head on over to the github repository that I've setup for the scripts for these screencasts. If we go to 02.md (and, yes, of course, I number them starting from 00) we can scroll down to very near the bottom of this script and copy the code. Then jump back to the terminal and open up your .bashrc file and paste the code right below the tab completion code for npm. Then, exit back out and source the .bashrc file and that should do it.
+Notice a hidden diectory in there that we didn't see before called `.bin`. If you take a look inside of there, you'll see a symbolic link that points right to the express command in the locally installed package. This `.bin` folder is where npm links all of the executables that each package provides. So, if we can just get that folder added to our PATH environment variable whenever we `cd` into a node application's directory, we would gain access to each package's command line programs without the need to install them globally, and that's exactly what the bash functions that I've created will do for you.
+
+I'm not going to go over the code for the bash functions here, since they're unrelated to our topic---however, if you're trully intersted, just ask in the comments and I'll be more than happy to post some notes on how the code works---but, for now, let's just head on over to the github repository that I've setup for these screencasts and grob a copy of those functions.
+
+If we go to 02.md (and, yes, of course, I number them starting from 00) we can scroll down to very near the bottom of this script and copy the code. Then jump back to the terminal and open up your .bashrc file and paste the code right below the tab completion code for npm. Then, exit back out and source the .bashrc file and that should do it.
Now if you cd out of the current directory and then back into it, the virtual environment should have been created. You can check by calling `echo $PATH` and making sure that the current directory has been added to the PATH variable, but you can also just call `express -h` again to make sure that we can call it. To further make sure, call `which express` to see that it is, in fact, calling the one stored in the local `node_modules/.bin`. The nice thing about the virtual environment code is that when you leave the node application's directory, it will reset your environment. So, if we cd back out of this directory and try to call `express -h` again, you'll notice we get the "command not found" error once again.
@@ -201,15 +205,17 @@ Now let's cd back into our app directory because we are going to finally install
The package that we're going to install is called supervisor and what it does is run a node service and restart it whenever a change has been made to it. So, we no longer have to shutdown our server and restart by hand everytime we make a change to our file, instead supervisor will now do that for us.
-Before we install the package though, let's clean up a bit, by getting rid of Express since we're not quite ready to use that library yet. Just type `npm uninstall express`. Next, let's do a search for supervisor since I don't quite remember if the package is called node-supervisor or supervisor. Type `npm search supervisor`. With this search, we get several packages back, but the first one in the list called simply supervisor looks like the one we want.
+Let's do a search for supervisor since I don't quite remember if the package is called node-supervisor or supervisor. Type `npm search supervisor`. With this search, we get several packages back, but the first one in the list called simply supervisor looks like the one we want.
So, if you added the virtual environment code from our last section to your .bashrc file, you can install the package locally by `npm install supervisor`. This package does provide a single executable, so you'll either want to use the virtual environment code or you'll want to install it globally.
-Now that we've got it installed, let's give it a try. In your apps directory, call `supervisor app.js`. That will start our app's server up. Then let's go to our browser and hit the new post form at http://localhost:8000/posts/new/. Now let's make a quick change to our app.js file to see how supervisor works. What I'm going to do is change the URL for our new post page from /posts/new to /posts/brandnew. Save that change and notice that supervisor has spit out something. It's telling us that the server has crashed and then restarted and is running once again on port 8000. If we now refresh our page in the browser, we see that the URL has indeed changed. Let's try out the new URL, and that looks good. Now let's go back over to our code and change the URL back and save. Supervisor once again stopped and restarted the server. Now we can change the URL in the browser back to new, and voila, there is our new posts page.
+Now that we've got it installed, let's give it a try. In your app's directory, call `supervisor app.js`. That will start our app's server up. Then let's go to our browser and hit the new post form at http://localhost:8000/posts/new/. Now let's make a quick change to our app.js file to see how supervisor works. What I'm going to do is change the URL for our new post page from /posts/new to /posts/brandnew. Save that change and notice that supervisor has spit out something. It's telling us that the server has crashed and then restarted and is running once again on port 8000. If we now refresh our page in the browser, we see that the URL has indeed changed. Let's try out the new URL, and that looks good. Now let's go back over to our code and change the URL back and save. Supervisor once again stopped and restarted the server. Now we can change the URL in the browser back to new, and voila, there is our new posts page.
## Conclusion
-Alright, well that pretty much wraps up everything. I know this has been a long episode, but there was just so much to cover. You've learned about what I consider to be the most important tools in the node developer's arsenal. NVM is a great way to manage multiple node versions on one machine, and if you don't know and understand npm, you're essentially going to be useless as a node developer. Finally, we installed and took a look at supervisor, a really handy little program that helps shrink our development time by making it possible to see our changes take effect immediately in the browser.
+Alright, well that pretty much wraps up everything. I know this has been a long episode, but there was just so much to cover.
+
+You've learned about what I consider to be the most important tools in the node developer's arsenal. NVM is a great way to manage multiple node versions on one machine, and if you don't know and understand npm, you're essentially going to be useless as a node developer. Finally, we installed and took a look at supervisor, a really handy little program that helps shrink our development time by making it possible to see our changes take effect immediately in the browser.
I hope that you've all gotten something out of this episode and I look forward to talking to you all again very soon.

0 comments on commit 86c59eb

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