Pug Tutorial Series

Pug.js tutorial : Learn how to install pug and pug-cli

Pug tutorial series pugjs tutorial introduction



Overview

In this part of the pug tutorial series we will learn about getting started with pug. We will learn how to install pug.

Prerequisites

Prerequisites for getting started with pug are as follows :

  1. Node.js : You can download it from here. After installation is done , we can check the version number of the installed node.js using the following command :
    											
    >node -v
    v8.5.0
    											
    										

    You can learn more about node.js from our node.js tutorial series 30 days of node .
  2. NPM : This will be installed automatically when you install node.js . You can check the version number of the installed npm using the following command :
    											
    >npm -v
    5.5.1
    											
    										

    You can learn more about npm here.
That's it. We are all set to install pug .

How to install

  1. Pug : Pug is available to install via npm using the following command :
    											
    >npm install pug -g
    											
    										

    here -g just signifies the global installation of pug npm package. You can install locally or gloablly as per your requirements.
  2. pug-cli : pug-cli npm package is used to render file/files or all files in a particular directory. Also if no files are specified it can take input from standard input and provides output on standard output
    											
    >npm install pug-cli -g
    											
    										

Options

Following are the options provided by pug-cli :

									
>pug -h
-h, --help             output usage information
-V, --version          output the version number
-O, --obj <str|path>   JSON/JavaScript options object or file
-o, --out <dir>        output the rendered HTML or compiled JavaScript to
                       <dir>
-p, --path <path>      filename used to resolve includes
-P, --pretty           compile pretty HTML output
-c, --client           compile function for client-side runtime.js
-n, --name <str>       the name of the compiled template (requires --client)
-D, --no-debug         compile without debugging (smaller functions)
-w, --watch            watch files for changes and automatically re-render
-E, --extension <ext>  specify the output file extension
-s, --silent           do not output logs
--name-after-file      name the template after the last section of the file
                       path (requires --client and overriden by --name)
--doctype <str>        specify the doctype on the command line (useful if it
                       is not specified by the template)
									
								

For example

Checking the version of the pug and pug-cli :

									
>pug -V
pug version: 2.0.0-rc.4
pug-cli version: 1.0.0-alpha6
									
								

What we learned

In this article we learn about the prerequisites for installing pug. We also learn how we can install pug and pug-cli . Also we learn about all the options provided by pug-cli with the help of a simple example.

Repository

You can clone all the snippets provided in this series from our github repo: