Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Clojurescript / node.js basic examples
(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
var express = require('express'),app = express.createServer()
app.get('/', function(req, res){
res.send('Hello World')
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 "")
(println "Server running at"))
(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) {
server (greetHandler,1337, "")
console.log('Server running at')
Copy link

ghost commented Dec 24, 2013

thanks :)

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