

pug extension, will have this icon properly identifying it. After you’ve successfully installed the Pug beautify plugin, each Pug file, which also ends in. The views folder is where everything related to Pug is going to be placed. This is how it should look: Project file and folders. Now, let’s guarantee that your folder and files structures match mine to avoid further errors. We’ll make use of axios as our HTTP client for the requests to the Random User API. The first is going to initialize our folder with a package.json, and the second will install the npm dependencies needed. In a folder of your choice, run the following commands: npm init -y Installing Pug beautify plugin in vscode. If you’re using Visual Studio Code as IDE, I recommend that you install the Pug beautify plugin since it is very helpful when it comes to code highlighting and snippets generation. The setup for this tutorial is pretty simple: we’ll only need Node.js and npm (which already comes within Node). This route will redirect to our Pug template, which will mount the final HTML output.īefore you proceed, I’d suggest inspecting the full source code of this Bootstrap example page so you can match each tag and CSS styles to the corresponding Pug ones. The structure will basically be composed of an Express server hosting our localhost application in Node.js that, in turn, will have only one route. It’s very useful when you don’t want to set up a whole structure of APIs only for testing or sampling. The data will be fetched from the Random User Generation API, a free API for generating random user data. We’re going to recreate the same structure and design, but in Pug only. The design was taken from one of the official Bootstrap’s examples (an Album example). The goal is, by the end of the article, to have the following: Final example. To infer style, let’s give it up to the power of Bootstrap. Instead, we’ll see how it works in practice by creating our own template from scratch. We’re not going to focus on its options, settings, and properties: for this, we already have the official docs, which are great. In this article, we’ll show you how Pug works.

If you’re familiar with Node.js, it’s a piece of cake. It’s simple, fast, and flexible with an easy syntax that simplifies not only the creation but also the reuse of HTML code.

But there are ports for other languages like Java, Python, Ruby, etc. Pug is a high-performance template engine heavily influenced by HTML and implemented with JavaScript for Node.js and browsers. With Pug, it’s a lot easier to reuse page pieces. In many cases, the use of a server side mechanism is necessary. HTML is just about static content made dynamic with many different tools and frameworks.Įven for static web sites, it’s tough to reuse page pieces that would be the same all over the website.

The time has arrived to create templates for our web pages.
