Skip to content

Instantly share code, notes, and snippets.

@azamsharp
Last active May 12, 2020 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azamsharp/892d684de0f41936787d96a14a33fce2 to your computer and use it in GitHub Desktop.
Save azamsharp/892d684de0f41936787d96a14a33fce2 to your computer and use it in GitHub Desktop.
const express = require('express')
const app = express()
const mustacheExpress = require('mustache-express')
// setting up Express to use Mustache Express as template pages
app.engine('mustache',mustacheExpress())
// the pages are located in views directory
app.set('views', './views')
// extension will be .mustache
app.set('view engine','mustache')
app.get('/',(req,res) => {
res.render('index')
})
// localhost:3000/
app.get('/hello',(req,res) => {
res.render('hello',{bookName: "Introduction to JavaScript", isbn: "123456"}) // display the hello.mustache page
})
app.listen(3000,() => {
console.log('Server is running...')
})
<html>
<head>
<title>{{bookName}}</title>
</head>
<body>
<h1>Welcome to Amazon</h1>
<h1>The name of the book is {{bookName}}</h1>
ISBN {{isbn}}
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment