Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Installing Global Packages2:52 with Andrew Chalkley
npm packages have more utility than being included locally in a project. There are other packages that can be installed as command line utilities. In this video I'll show you how to install one such utility: http-server.
- Clear the screen
npm Command Line Usage
Get help for a command
npm <command> -h
npm install -h
Installing a global package
npm install <package_name> -g
npm install http-server -g
Treehouse Node.js and npm Install Guides
When you want to use a package in a particular project, 0:00 it makes sense to install it with the other files for that project. 0:03 However, some packages like command-line apps or 0:06 utilities, are handy for lots of projects. 0:09 For example, the http-server package, 0:12 makes it easy to start a simple web server on your computer. 0:15 You can use it to test any of your static sites. 0:19 Because you could use this package for 0:22 any web project, it make sense to install it so it's always available. 0:24 We call these kinds of always available packages, a global package. 0:28 To install a package globally we use npm install. 0:34 The package net, http-server and -g, which means global. 0:38 Hit Enter, and we have an issue. 0:44 We don't have permissions or access to install this globally. 0:50 For security, we limit how much you can do on the command line in workspaces. 0:55 However, you might run into a similar issue 1:01 even if you've installed npm on your own computer. 1:04 I have included a link in the teacher's notes to show you how to solve 1:07 these issues. 1:10 But if you followed the Treehouse and store guides, you wouldn't have had 1:12 a problem like this because of the ways that we recommend you install npm. 1:16 See the teacher's notes for links to those install guides, too. 1:20 To demonstrate installing a global package, 1:24 I'll use the terminal application on this computer and not Workspaces. 1:27 I'll run npm install. 1:32 Http-server -g. 1:37 And this time, it installs correctly. 1:44 I have also got a folder here with the simple AJAX site, 1:50 that doesn't work if you double click on the index to HTML. 1:53 For security, most browsers won't accept AJAX requests if you just open a file 1:59 in the browser with the file protocol. 2:04 However, if you view the webpage from a web server, AJAX requests will work. 2:10 So I'm going to use the http-server to start up a web server so 2:16 I can view the site. 2:21 We can do that just by typing http-server followed by the folder we want to serve. 2:24 We can copy the URL. 2:35 And paste it into a web browser. 2:41 And now it works. 2:43 Http-server is a super handy command line app that can be installed through npm. 2:44 And there's countless more where that came from. 2:50
You need to sign up for Treehouse in order to download course files.Sign up