Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
evented io webserver right inside your emacs.
tree: e3a6554832

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
test_docroot
README.creole
elnode.el
ertelnodetests.el

README.creole

elnode

An attempt to make an emacs lisp clone of nodejs.

Apparently Steve Yegge has already done this... but I couldn't find it so I'm writing it.

Why elnode??

It's like "hell, no". It's... well.... it's an, um, joke.

How does it work?

Well... you can define a handler function:

(defun nicferrier-handler (httpcon)
  "Demonstration function"
  (elnode-http-start httpcon "200" '("Content-type" . "text/html"))
  (elnode-http-return httpcon "<html><b>HELLO!</b></html>")
  )

And then start the server:

(elnode-start 'nicferrier-handler 8000)

You can also start the server interactively... you still have to pass it a handler function and a port.

Stopping the server

If you can remember the port you started your server on then you'll be able to stop it, like:

(elnode-stop 8000)

HTTP interface

headers

You can query headers in the HTTP request in your handler using the function elnode-http-header:

(defun my-handler (httpcon)
  (elnode-http-header httpcon "Content-type")
  )

method

(elnode-http-method httpcon)

pathinfo

(elnode-http-pathinfo httpcon)

query

(elnode-http-query httpcon)

query parameters

(elnode-http-params httpcon)

this returns an alist of the params in the query.

version

(elnode-http-version httpcon)

Dispatching

Handler functions can be simple functions to respond to everything coming into a server. It's more normal that you would have a server that did different things on different urls so elnode provides a url dispatcher function, you can use it like this:

  (elnode-dispatcher httpcon
                     '(("/$" . 'root-handler)
                       ("users/$" . 'users-handler))))

One of the chief advantages of any lisp is the amount of flexibility there can be in code like this. If elnode is at all successfull at catching people's imaginations I would expect a variety of dispatchers to emerge.

Calling processes

There is early support for calling unix processes asynchronously:

(elnode-child-process httpcon 
    "cat" "/home/nferrier/elnode/example.html"
    )

Would call the program cat with the HTML file as an argument. The output of the process will be copied to the HTTP connection asychronously (so fast).

Again, lot's of improvement needed here but this does work quite well.

But...

There's always a but.

The HTTP parsing isn't very complete, we don't parse any data sent through POST.

That stuff is coming soon.

Something went wrong with that request. Please try again.