Skip to content

Instantly share code, notes, and snippets.

@terkhorn
Forked from jneira/express-sample.cljs
Created September 11, 2013 21:14
Show Gist options
  • Save terkhorn/6529875 to your computer and use it in GitHub Desktop.
Save terkhorn/6529875 to your computer and use it in GitHub Desktop.
(ns express_sample
(:require [cljs.nodejs :as node]))
(def express (node/require "express"))
(def app (. express (createServer)))
(defn -main [& args]
(doto app
(.use (. express (logger)))
(.get "/" (fn [req res]
(.send res "Hello World")))
(.listen 3000))
(println (str "Express server started on port: "
(.port (. app (address))))))
(set! *main-cli-fn* -main)
// from http://blog.nodeknockout.com
var express = require('express'),app = express.createServer()
app.use(express.logger())
app.get('/', function(req, res){
res.send('Hello World')
})
app.listen(3000)
console.log('Express server started on port %s', app.address().port)
(ns helloserver
(:require [cljs.nodejs :as nodejs]))
(def http (nodejs/require "http"))
(defn greetHandler [req res]
(doto res
(.writeHead 200 {"Content-Type" "text/plain"})
(.end "Hello World")))
(defn server [handler port url]
(-> (.createServer http handler)
(.listen port url)))
(defn -main [& mess]
(server greetHandler 1337 "127.0.0.1")
(println "Server running at http://127.0.0.1:1337/"))
(set! *main-cli-fn* -main)
var http = require('http')
function greetHandler (req,res) {
res.writeHead (200,{'Content-Type': 'text/plain'})
res.end('Hello World\n')
}
function server (handler,port,url) {
http.createServer(handler).listen(port,url)
}
server (greetHandler,1337, "127.0.0.1")
console.log('Server running at http://127.0.0.1:1337/')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment