Skip to content

Instantly share code, notes, and snippets.

@troygoode
Last active December 29, 2020 17:14
Show Gist options
  • Save troygoode/5851859 to your computer and use it in GitHub Desktop.
Save troygoode/5851859 to your computer and use it in GitHub Desktop.
basic example node.js (+express +jade) application configured to run in Heroku (views_layout.jade and views_home.jade should just be "layout.jade" and "home.jade" inside the "views" subdirectory) (public_home.js should just be "home.js" inside the "public" subdirectory)
{
"name": "example",
"version": "0.0.1",
"private": true,
"engines": {
"node": "0.10.x",
"npm": "1.2.x"
},
"dependencies": {
"express": "*",
"jade": "*"
}
}
web: node server.js
$(function(){
alert('Hello world.');
});
var express = require('express');
var app = module.exports = express();
app.set('view engine', 'jade');
app.set('views', __dirname + '/views');
app.use(express.static(__dirname + '/public'));
app.use(app.router);
app.get('/', function(req, res){
res.render('home', {sayHelloTo: 'world'});
});
if(!module.parent){
app.listen(process.env.PORT || 3000, function(){
console.log('up and running');
});
}
extends layout
block title
title Overriden Example
block scripts
script(src="http://code.jquery.com/jquery-1.10.0.min.js")
script(src="/home.js")
block content
p Hello #{sayHelloTo}.
doctype 5
html(lang="en")
head
block title
title Example
block stylesheets
body
block body
block scripts
@HelloWorldForBeginners
Copy link

HelloWorldForBeginners commented Jan 9, 2017

Thanks for the gist, Troy. However, it looks like there have been some changes since you posted, and with this example, Heroku is throwing errors on page load.

2017-01-09T03:06:11.211213+00:00 heroku[web.1]: State changed from starting to crashed
2017-01-09T03:06:11.192170+00:00 heroku[web.1]: Process exited with status 8
2017-01-09T03:06:12.338190+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=someapp.herokuapp.com request_id=4d62ef68-38e1-4dae-b449-123642d186d1 fwd="x.x.x.x" dyno= connect= service= status=503 bytes =

When running from the heroku console, it talks about deprecation of app.router

$ heroku run bash
Running bash on ⬢ someapp... up, run.3105 (Free)
~ $ ls
Procfile  node_modules  package.json  public  server.js  views
~ $ node server.js 

Error: 'app.router' is deprecated!
Please see the 3.x to 4.x migration guide for details on how to update your app.
    at EventEmitter.Object.defineProperty.get (/app/node_modules/express/lib/application.js:123:13)
    at Object.<anonymous> (/app/server.js:8:12)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:945:3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment