From d3685b05bc8747ac369571ee45f3c04973cec38c Mon Sep 17 00:00:00 2001 From: Marian Oancea Date: Wed, 3 Dec 2014 05:08:49 +0200 Subject: [PATCH] initial commit --- app.js | 61 +++++++++++++++++++++++++++++++++++ bin/www | 9 ++++++ package.json | 18 +++++++++++ public/stylesheets/style.styl | 5 +++ routes/index.js | 9 ++++++ routes/users.js | 9 ++++++ views/error.jade | 6 ++++ views/index.jade | 5 +++ views/layout.jade | 7 ++++ 9 files changed, 129 insertions(+) create mode 100644 app.js create mode 100755 bin/www create mode 100644 package.json create mode 100644 public/stylesheets/style.styl create mode 100644 routes/index.js create mode 100644 routes/users.js create mode 100644 views/error.jade create mode 100644 views/index.jade create mode 100644 views/layout.jade diff --git a/app.js b/app.js new file mode 100644 index 0000000..4f6e0d8 --- /dev/null +++ b/app.js @@ -0,0 +1,61 @@ +var express = require('express'); +var path = require('path'); +var favicon = require('serve-favicon'); +var logger = require('morgan'); +var cookieParser = require('cookie-parser'); +var bodyParser = require('body-parser'); + +var routes = require('./routes/index'); +var users = require('./routes/users'); + +var app = express(); + +// view engine setup +app.set('views', path.join(__dirname, 'views')); +app.set('view engine', 'jade'); + +// uncomment after placing your favicon in /public +//app.use(favicon(__dirname + '/public/favicon.ico')); +app.use(logger('dev')); +app.use(bodyParser.json()); +app.use(bodyParser.urlencoded({ extended: false })); +app.use(cookieParser()); +app.use(require('stylus').middleware(path.join(__dirname, 'public'))); +app.use(express.static(path.join(__dirname, 'public'))); + +app.use('/', routes); +app.use('/users', users); + +// catch 404 and forward to error handler +app.use(function(req, res, next) { + var err = new Error('Not Found'); + err.status = 404; + next(err); +}); + +// error handlers + +// development error handler +// will print stacktrace +if (app.get('env') === 'development') { + app.use(function(err, req, res, next) { + res.status(err.status || 500); + res.render('error', { + message: err.message, + error: err + }); + }); +} + +// production error handler +// no stacktraces leaked to user +app.use(function(err, req, res, next) { + res.status(err.status || 500); + res.render('error', { + message: err.message, + error: {} + }); +}); + + +module.exports = app; diff --git a/bin/www b/bin/www new file mode 100755 index 0000000..e77df43 --- /dev/null +++ b/bin/www @@ -0,0 +1,9 @@ +#!/usr/bin/env node +var debug = require('debug')('eth-netstats'); +var app = require('../app'); + +app.set('port', process.env.PORT || 3000); + +var server = app.listen(app.get('port'), function() { + debug('Express server listening on port ' + server.address().port); +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..99d532f --- /dev/null +++ b/package.json @@ -0,0 +1,18 @@ +{ + "name": "eth-netstats", + "version": "0.0.0", + "private": true, + "scripts": { + "start": "node ./bin/www" + }, + "dependencies": { + "express": "~4.9.0", + "body-parser": "~1.8.1", + "cookie-parser": "~1.3.3", + "morgan": "~1.3.0", + "serve-favicon": "~2.1.3", + "debug": "~2.0.0", + "jade": "~1.6.0", + "stylus": "0.42.3" + } +} \ No newline at end of file diff --git a/public/stylesheets/style.styl b/public/stylesheets/style.styl new file mode 100644 index 0000000..1377e2f --- /dev/null +++ b/public/stylesheets/style.styl @@ -0,0 +1,5 @@ +body + padding: 50px + font: 14px "Lucida Grande", Helvetica, Arial, sans-serif +a + color: #00B7FF \ No newline at end of file diff --git a/routes/index.js b/routes/index.js new file mode 100644 index 0000000..896c948 --- /dev/null +++ b/routes/index.js @@ -0,0 +1,9 @@ +var express = require('express'); +var router = express.Router(); + +/* GET home page. */ +router.get('/', function(req, res) { + res.render('index', { title: 'Express' }); +}); + +module.exports = router; diff --git a/routes/users.js b/routes/users.js new file mode 100644 index 0000000..c00d7de --- /dev/null +++ b/routes/users.js @@ -0,0 +1,9 @@ +var express = require('express'); +var router = express.Router(); + +/* GET users listing. */ +router.get('/', function(req, res) { + res.send('respond with a resource'); +}); + +module.exports = router; diff --git a/views/error.jade b/views/error.jade new file mode 100644 index 0000000..51ec12c --- /dev/null +++ b/views/error.jade @@ -0,0 +1,6 @@ +extends layout + +block content + h1= message + h2= error.status + pre #{error.stack} diff --git a/views/index.jade b/views/index.jade new file mode 100644 index 0000000..3d63b9a --- /dev/null +++ b/views/index.jade @@ -0,0 +1,5 @@ +extends layout + +block content + h1= title + p Welcome to #{title} diff --git a/views/layout.jade b/views/layout.jade new file mode 100644 index 0000000..b945f57 --- /dev/null +++ b/views/layout.jade @@ -0,0 +1,7 @@ +doctype html +html + head + title= title + link(rel='stylesheet', href='/stylesheets/style.css') + body + block content \ No newline at end of file