Lightweight literal programming

npm install literate
4 downloads in the last week
8 downloads in the last month


Write your code in markdown, then use literate to 'require' the module. The JavaScript you have written in code blocks will be scraped out and returned as the module at runtime.


$ npm install literate

Example Usage

Creating a markdown module

Create a markdown file for you documenation and code (

# This is an example module.

First it logs to the console:

    console.log("hello world")

It exports a function as an example.

    module.exports.useAsNormal = function(){
      return "foo";

You can also set a variable like this `var x = 2`, 
and write it out with a `console.log(x)`.

Calling the module

In your main file (server.js), instead of using require directly, use literate to load the module:

var your_module = require('literate')('./your_module');

Runtime inspection of the Markdown

The markdown is available to the module at runtime on a __markdown variable:

# Retrieve documentation at runtime

    module.exports.markdown = function(){
      return __markdown;


At the moment block are not supported, so you have to write your program in sequence.



npm loves you