Converts Javascript into Pug

Usage no npm install needed!

<script type="module">
  import js2pug from 'https://cdn.skypack.dev/js2pug';



Converts Javascript into Pug

This program converts a normal Javascript file into a Pug file (formerly Jade), containing unbuffered block code.

This is useful if you want to write your (server-side) Pug data in actual Javascript.

Installation & Usage

Command Line

To run from the command line, install globally.

$ npm install -g js2pug
$ js2pug [--jade] file.js

where file.js is the name of your source file (relative path), and file.js.pug will be the name of the output file (in the same directory).

The --jade option specifies .jade instead of .pug for the output file extension.


To use in your own node module, install as a dependency.

$ npm install --save[-dev] js2pug
var js2pug = require('js2pug')

js2pug('file.js')       // file.js -> file.js.pug
js2pug('file.js', true) // file.js -> file.js.jade

The function js2pug() returns undefined. (This may change at a later time.)


src: file.js:

var MyClass = (function () {
  function MyClass() {
  return MyClass

out: file.js.pug or file.js.jade:

  var MyClass = (function () {
    function MyClass() {
    return MyClass


On GitHub.