How to solve this jade error?


I'm just getting started on nodeJS and I'm using JADE as view engine , I'm just doing tests, nothing extraordinary, and yet throws the following error:

(function (exports, require, module, __filename, __dirname) { 

SyntaxError: Invalid or unexpected token
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:616:28)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\Users\Familia\Documents\node\expres\node_modules\jstransformer\index.js:5:15)

My code is the following app.js :

var express = require("express");

var app = express();

app.set("view engine", "jade");

app.get("/",(req, res)=>{

And this is the index.jade :

        title "mi primera página con jade"
        h1 "Hola Mundo"
asked by joskar hernandez 01.04.2018 в 23:25

1 answer


A couple of details about your code

  • jade is a template engine that is discontinued and in the near future you should try Pug which is the version that was born
  • You need to declare the variable that will contain the path (this is needed so that the call to your files is done as an absolute path, regardless of whether you change the name of the folder)
  • I did not see that you installed jade, so you must first do npm i -S jade
  • Declares a jade variable that contains the call to the jade module
  • In the res.render add the path.join
  • Look at this code for your .js file

    var express = require("express");
    var jade = require("jade")
    var path    = require("path");
    var app = express();
    app.set('view engine', 'jade')
    app.get("/", function(req, res){

    For your Jade file, I'll give you this example, where as you can notice this incpmpleta your declaration of the labels and considering that jade compiles them and then shows an HTML that's why it also gives error

    doctype html
        title= pageTitle
        h1 Jade 
            Hola a Todos

    If for example copy and paste this code as it is, from the   console at the level of the folder that contains your project, you must make a npm install to run and install the   dependencies that you need

    Regarding the PUg template engine, I leave you 2 links; the first one is to see its download and installation process


    The second one is for you to see from its official site how it is used


    answered by 01.04.2018 / 23:53