Last active
November 27, 2020 09:18
-
-
Save remoharsono/c855dd4e39410d6ff5323b3aff84f542 to your computer and use it in GitHub Desktop.
Express with Pug and Nodemon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// no changes to express-part1 | |
npm init | |
npm install --save express | |
npm install --save pug | |
npm install --save-dev nodemon | |
> vi package.json | |
--------------------- | |
package.json [before] | |
--------------------- | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
--------------------- | |
--------------------- | |
package.json [after] | |
--------------------- | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1", | |
"start": "nodemon index.js" | |
}, | |
--------------------- | |
> vi index.js | |
---------- | |
index.js | |
---------- | |
var express = require('express'); | |
var app = express(); | |
app.set("view_engine", "pug"); | |
app.get('/', function(req, res){ | |
myvar = { title: 'Judul', message: 'Halo Purbalingga'}; | |
res.render("index.pug", myvar); | |
}); | |
app.listen(8000, function(){ | |
console.log('Server started on port 8000') | |
}); | |
--------------------------------------- | |
> mkdir views | |
> cd views | |
> vi index.pug | |
------------ | |
index.pug | |
----------- | |
html | |
head | |
title= title | |
body | |
h1= message | |
--------------------------------------- | |
> node index.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment