Skip to content

Instantly share code, notes, and snippets.

@remoharsono
Last active November 27, 2020 09:18
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 remoharsono/c855dd4e39410d6ff5323b3aff84f542 to your computer and use it in GitHub Desktop.
Save remoharsono/c855dd4e39410d6ff5323b3aff84f542 to your computer and use it in GitHub Desktop.
Express with Pug and Nodemon
// 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