0

How can I write nodejs (with and without express framework) app that do such think in php:

<doctype hyml>
<html>
<body>
<h1> <?php echo "Hi"; ?> </h1>
</body>
</html>

with or without express.js.

1 Answer 1

2

You will have to setup your node.js project to use a template engine like jade.

app.js

By doing that you need to install jade with npm and require the dependency into your project.

var express = require('express');
var jade = require('jade');
var app = express();

Then you have to tell express.js to use the jade template engine.

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

Then you use the render function to render the index.jade with the second param as an object.

app.get('/', function(req, res) {
    res.render('index', {
        msg: 'Hi'
    });
}

views/index.jade

The #{msg} placeholder will then be compiled into 'Hi'.

html
    body
        h1 #{msg}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.