Jade is a high-performance templating engine that is heavily influenced by Haml, implemented in JavaScript and available for Node. It is also very simple and easy to learn.

Let’s now look at how to make the simplest NodeJS Hello World application using Jade.

Add a dependency on Jade to nodejs’ package.json:

Use the following code in the nodejs code to set the view engine used by the app instance returned by Express:

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine'.'jade');
Copy the code

Set the view to render as shown below, named index:

router.get('/'.function(req, res, next) {
  res.render('index', { title: 'CoreSystem Proxy Project' });
  res.send('hahahaha,my god! ');
});
Copy the code

Create a new view template named index.jade in the Views folder with the following content:

extends layout

block content
  h1= title
  p Welcome to #{title}
Copy the code

The variable title in the template source file wrapped with a pound sign and braces is replaced at run time by the value of the model field title: CoreSystem Proxy Project, as shown below:

For more of Jerry’s original articles, please follow the public account “Wang Zixi “: