Browse files

expressjs-coffeescript-example

  • Loading branch information...
0 parents commit 2d59bf8398dcd69b8c76e67da3101952d50bb9fa @jivko committed Mar 28, 2013
Showing with 68 additions and 0 deletions.
  1. +12 −0 package.json
  2. +8 −0 public/stylesheets/style.css
  3. +2 −0 routes/index.coffee
  4. +2 −0 routes/user.coffee
  5. +33 −0 server.coffee
  6. +11 −0 views/index.ejs
12 package.json
@@ -0,0 +1,12 @@
+{
+ "name": "application-name",
+ "version": "0.0.1",
+ "private": true,
+ "scripts": {
+ "start": "node app"
+ },
+ "dependencies": {
+ "express": "3.1.0",
+ "ejs": "*"
+ }
+}
8 public/stylesheets/style.css
@@ -0,0 +1,8 @@
+body {
+ padding: 50px;
+ font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
+}
+
+a {
+ color: #00B7FF;
+}
2 routes/index.coffee
@@ -0,0 +1,2 @@
+exports.index = (req, res) ->
+ res.render "index", title: "Express"
2 routes/user.coffee
@@ -0,0 +1,2 @@
+exports.list = (req, res) ->
+ res.send "respond with a resource"
33 server.coffee
@@ -0,0 +1,33 @@
+express = require('express')
+routes = require('./routes')
+user = require('./routes/user')
+http = require('http')
+path = require('path')
+
+app = express()
+
+app.configure ->
+ publicDir = "#{__dirname}/public"
+ viewsDir = "#{__dirname}/views"
+
+ app.set "port", process.env.PORT || 3000
+ app.set "views", viewsDir
+ app.set "view engine", "ejs"
+ app.use express.favicon()
+ app.use express.logger('dev')
+ app.use express.bodyParser()
+ app.use express.methodOverride()
+ app.use express.cookieParser('pix_js_secret')
+ app.use express.session()
+ app.use app.router
+ app.use express.static(publicDir)
+
+app.configure "development", ->
+ app.use express.errorHandler()
+
+app.get "/", routes.index
+app.get "/user", user.list
+
+http.createServer(app).listen(app.get('port'), ->
+ console.log "Express server listening on port " + app.get('port')
+)
11 views/index.ejs
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title><%= title %></title>
+ <link rel='stylesheet' href='/stylesheets/style.css' />
+ </head>
+ <body>
+ <h1><%= title %></h1>
+ <p>Welcome to <%= title %></p>
+ </body>
+</html>

0 comments on commit 2d59bf8

Please sign in to comment.