Skip to content

Instantly share code, notes, and snippets.

@semperos
Created December 31, 2014 17:20
Show Gist options
  • Select an option

  • Save semperos/83696c0ac168eb03ab1d to your computer and use it in GitHub Desktop.

Select an option

Save semperos/83696c0ac168eb03ab1d to your computer and use it in GitHub Desktop.
NodeJS Server "Hello, World" at ClojureScript REPL
;; David Nolen announced NodeJS REPL support for ClojureScript: http://swannodette.github.io/2014/12/29/nodejs-of-my-dreams/
;; This is a short interactive session that implements the NodeJS server "Hello, World",
;; featured on the NodeJS home page: http://nodejs.org/#column1
;; At command-line:
;; git clone https://github.com/clojure/clojurescript
;; cd clojurescript
;; ./script/bootstrap
;; ./script/self-compile
;; npm install source-map-support
;; # Make sure to use Node v0.10.x, not v0.11.x
;; ./script/noderepljs
;; To quit, type: :cljs/quit
;; ClojureScript Node.js REPL server listening on 5001
;; ClojureScript:cljs.user>
(def http (js/require "http"))
;=> a lot of stuff you don't want to see
(def head (clj->js {"Content-Type" "text/plain"}))
;=> #js {:Content-Type "text/plain"}
(def server (.createServer http (fn [req resp] (.writeHead resp 200 head) (.end resp "Hello, World\n"))))
;=> #<[object Object]>
(.listen server 1337 "127.0.0.1")
;=> #<[object Object]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment