Question

I just started looking into NodeJS and Express and found out about the possibility to generate a new app that uses hogan right from the start:

express <appname> -c [stylus, less] --hogan --ejs

Is there a way to generate a new app that uses CoffeeScript, HAML instead of Jade and Less/SCSS ?

Was it helpful?

Solution

I don't think there is a generator, but you can easily make an express app using HAML and coffeescript.

package.json:

{
  "name": "haml-coffee-express",
  "dependencies": {
    "express": "",
    "express-partials": "",
    "haml-coffee": "",
    "coffee-script": ""
  }
}

server.coffee:

express = require("express")
partials = require("express-partials")
app = express()
app.engine "hamlc", require("haml-coffee").__express 
app.use partials()

app.set "view engine", "hamlc"

app.get "/", (req, res) ->
  res.render "index",
  name: "User"

app.listen 3000
console.log "App started on port 3000"

views/layout.hamlc:

!!!
%head
  %title Express App
%body
  != @body

views/index.hamlc:

%h1= "Welcome #{ @name }"
%p You've rendered your first Haml Coffee view.


Afterwards, just run this command and you are good to go.

npm install && node_modules/coffee-script/bin/coffee server.coffee

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top