Appendix D. Installing Node.js and Gulp.js

This appendix covers

  • Installing Node.js
  • Installing Gulp.js

Gulp.js is a JavaScript-based tasked runner that runs in Node.js. This appendix guides you through installing these two applications.

D.1. Installing Node.js

Apart from Gulp.js, chapter 9 has another fundamental requirement. Gulp.js runs on Node.js, so you need to have that installed to follow along. You can find Node.js at https://nodejs.org/download. At the Node.js site, you can also find the installer that matches your system. After you’ve installed it, you can verify its installation by typing node –v from the command line:

C:> node –v
V0.12.2

This tells you the version that was installed, and getting a proper response confirms the installation. With Node.js installed, you’re ready for your first look at Gulp.js.

D.2. Installing Gulp.js

To get started with Gulp.js, you first need to install it. With Node.js installed, this is easy. You’ll use the package manager (npm) that comes with Node.js (version 0.6 or higher). With npm, you can use a simple command from the command line to download and install Gulp.js.

In npm, what you install is called a package. Packages can be installed locally or globally (or both). You’ll use the –g option to install Gulp.js globally so you can run its commands from any directory. From the command line, run npm install –g gulp.

Note

If you’re using OS X or Linux, it’s recommended that you avoid using sudo when installing packages. See https://docs.npmjs.com/getting-started/fixing-npm-permissions.

If the process is successful, you should see output in the console similar to figure D.1.

Figure D.1. Installing Gulp.js

As you did with Node.js, you can confirm the installation by checking the version installed via the –v command: gulp –v. With the ability to run Gulp.js commands from anywhere, switch to your project directory. Here you’ll install any packages specifically needed for your project.

Note

To include metadata about your Node.js project, including information about your build’s dependencies and their versions, you’ll need to create a package.json file. The npm package manager can use the version field in this file to make sure the correct version of your packages gets installed. Additionally, if this file is present, information about the package being installed will be added to a list of dependencies if you use the --save or --save-dev options with the npm install command. The --save option can be used to specify runtime dependencies (when the application is used, such as your MV* framework), and the --save-dev option is for development dependencies. Although the dependency listings inside the file will be updated automatically during the installation of your packages using the options mentioned, you’ll need to create the initial package.json file. You can do that manually or use the command npm init. If you need guidance in creating the package.json file, this command will walk you through the process by asking several questions. Feel free to edit the generated file as needed. After the process has completed, you’ll have the initial package.json file created with the defaults you specified.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset