Simple node express web server Pt.2
Created on: Tue Jul 18 2017
So you created a simple node web server with express, and you can see your sent text on screen. But you're far from a working site, you'll need to add some actual html to these rendered urls. In steps HandleBars.

npm install hbs --save

Then create in your projects root directory, a 'views' directory (this is where your page templates will reside), and inside the 'views' directory create a 'partials' directory for your 'header.hbs' and 'footer.hbs' files. Now create those header.hbs and footer.hbs files: Header:

DOCTYPE html html head title{{pageTitle}}/title /head body

Footer:

/body /html

Then you index.hbs:

{{> header}} h1 Welcome /h1 {{> footer}}

const express = require('express'); const hbs = require('hbs'); var app = express(); app.set('view engine', 'hbs');// Set handlebars as the view engine hbs.registerPartials(__dirname + '/views/partials');// Directory for your header and footer files. app.get('/', (req, res) => { res.render('index', {pageTitle: "My Home Page"}); }); app.listen(3000, ()=>{ console.log('Server started on http://localhost:3000'); });

That's it. Go to http://localhost:3000 and view your new node/express web server.
 #NODE.js |  #Express |  #node |  #express |