Week 4 - ExpressJS framework & templates

More Heroku and webservers with ExpressJS web framework. Organizing web applications, separating code and design with routes and templates.


Heroku

Foreman

Foreman is a tool installed with Heroku toolbelt https://toolbelt.heroku.com. Foreman is a process manager, meaning, it can start our application in the same way Heroku does.

Procfile

Profile is the command that Foreman runs when we run foreman start

Procfile

web: node app.js

Running Local Server

Inside your Terminal, navigate into your code directory.

cd ~/Desktop/myapp

Or where ever your app directory is located.

Start the server

foreman start

ExpressJS

ExpressJS (http://expressjs.com/) is a web framework for NodeJS. It is considered a micro-framework, like Ruby's Sinatra or Python's Flask.

Web frameworks provide commonly used functions for URL routing, templates, sessions and extending functionality with third party libraries.

ExpressJS is usually structured with several files and directories.

  • app.js - this is the main application code that starts the server, requires all the needed libraries, connects to remote services like a database and general configuration for how the server will operate.

  • /routes - this directory will contain the .js files that define the callback functions for your URL routes.

  • /views - this directory will contain your templates. We are using the hogan-express template engine - the template files we write will include the hogan/mustache markup to put dynamic variables into our HTML files.

  • /public - all static assets go here. CSS, client side JavaScript files, images, etc.

ExpressJS and Templates Demo

* Demo itpdwdexpresstemplates.herokuapp.com

* Github Code




Assignment

Using the example code make your web app look presentable with HTML and CSS.

You should have at least 3 pages. Bonus points* for form submission using HTTP POST. Push your web app to Heroku when finished.

* Bonus points probably don't exist.

comments powered by Disqus