Training Guide: Programming in HTML5 with JavaScript and CSS3 Ebook

(Nora) #1

Lesson 1: Getting started with Node.js CHAPTER 8 349


The following functions are available in the math_example package.  


  • addition Adds two numbers and returns the result.  

  • subtraction Subtracts the second number from the first and returns the result.  

  • multiplication Multiplies two numbers and returns the result.  

  • division Divides the first number by the second number and returns the result.  

  • fibonacci Applies the fibonacci sequence count times and returns the result.  


The formatting is very readable. When it’s rendered to HTML, it’s also very readable, as
shown in the live view window in Figure 8-3.

FIGURE 8-3 diting the README.md file using MarkdownPadE

Creating the package.json file
The package.json file is the manifest for your package. This file contains the metadata that
describes your package. You can create this file manually, but an easier way to create the file
is to type the following command.
npm init

When you run this command, it leads you through a series of prompts, and then the file is
created for you. You can always edit the file later if needed.
As the file extension implies, this file is written in JSON, which is JavaScript Object
Notation. The following is the package.json file for math_example.
{
"name": "math_example",
"version": "0.0.0",
"description": "An example of creating a package",
"main": "bin/main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": "",
"keywords": [
"math",
"example",
Free download pdf