- Render pug template with javascript how to#
- Render pug template with javascript install#
- Render pug template with javascript code#
We executed node app.js in the terminal to get this output. The web server const express = require('express') const app = express() app.listen(3000, () => console.log(“Listening on port 3000”)) In this file, we create an HTTP server and it listens on port 3000. We are ready to start! Let’s create the app.js file in the root folder. Express is a middleware web framework that handle routes, requests and responses. The dependencies we just installed serve different purposes.
Render pug template with javascript install#
Let’s install Nodejs and other dependencies we need in the project, once it is done running it adds node modules folder and package-lock.json file: Every dependency you add in this project will show in the package.json file. You have successfully created a package.json file, located in the root folder of your project, for project identification and contain dependencies we will install add. package name: (newproject) version: (1.0.0) description: entry point: (index.js) app.js test command: git repository: keywords: author: license: (ISC) The dependencies
However you can specify all the fields, read more about the content of the package.json fields here to make informed changes.
Render pug template with javascript code#
By running the code below, we initiate our project by creating a package.json file.Īs shown below, I did not change anything except entry point, I changed from index.js (default) to app.js. I recommend using the terminal in vsCode because it is easier to access, you do not need to enter the path directory. Open the folder newProject in Visual Studio Code (VSCode). Use the IDE of your choice, in my case I am using Visual Studio Code. Start by creating a folder in a directory of your choice using the terminal.
In addition to the prerequisite mentioned above, you must be familiar with JavaScript. Click here to get Nodejs if you do not have one. To get hands on experience with this article you need to have:
Render pug template with javascript how to#
At the end of this tutorial, you would have created an single web page and learn how to use the technologies mentioned above. We will create a Node application from scratch, set up Nodejs, express, and a pug template engine. In this tutorial, I will explain how to use a pug template and NodeJS to build a web page. Image by Free-Photos from Pixabay Introduction The pug-plugin enable to use script and style source files directly in Pug, so easy:Ĭonst path = require ( 'path' ) const PugPlugin = require ( 'pug-plugin' ) module. The pug-plugin already contains the pug-loader, not need to install an additional Pug loader. Install the pug-plugin: npm install pug-plugin -save-dev It is non-intuitive and very complex way.įor details and examples please see the pug-plugin site.