Exercise 2: Installing Packages and Using Packages with Node.js

Learning Objectives

  • install a package using npm
  • use package in a Node.js program using require

Prerequisites

  • you should have Node.js >= v4 installed
  • you should have npm v2 or v3 installed

Instructions

  1. Create a directory called my-project
  2. Change into that directory using cd my-project
  3. Install the my-first-mod
  4. Create a file called index.js
  5. Use the my-first-mod to add the numbers 3 and 4
  6. Use the my-first-mod to have the console print Hello, <your name>!

Hints

  • You can use http://npmjs.com to look at the README of a package. A README will often give you information on how to use the package.
  • You can use console.log(<string>) to print things to the console with Node.js, where <string> is a set of characters or a variable that contains a set of characters
  • You can run a Node.js program by typing node <js-file-name> where js-file-name is the name of a .js file, e.g. index, index.js

results matching ""

    No results matching ""