Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 131 lines (81 sloc) 2.83 kb


Bindings to Mapnik for node.

var mapnik = require('mapnik');
var http = require('http');

var port = 8000;
var stylesheet = './examples/stylesheet.xml';

http.createServer(function(req, res) {
  res.writeHead(500, {'Content-Type': 'text/plain'});
  var map = new mapnik.Map(256, 256);
    function(err,map) {
      if (err) {
      var im = new mapnik.Image(256, 256);
      map.render(im, function(err,im) {
        if (err) {
        } else {
            im.encode('png', function(err,buffer) {
                if (err) {
                } else {
                    res.writeHead(200, {'Content-Type': 'image/png'});

Note: to run this example locally first do:

export NODE_PATH=./lib:${NODE_PATH}

For more sample code see 'examples/'


  • Node >= v0.6.0
  • Mapnik 2.1-dev (current master): (at least 207ecfd597 / March 12, 2012)


First install Mapnik master from github:

git clone

For more details see:

Confirm that the mapnik-config program is available and on your $PATH.

To install node-mapnik locally for development or testing do:

git clone git://
cd node-mapnik

Then, if you have expresso installed you can run the tests:

make test

Or set NODE_PATH to test importing:

export NODE_PATH=./lib
node -e "require.resolve('mapnik')"

Or you can also install via npm

npm install mapnik

The above will install node-mapnik locally in a node_modules folder. To install globally do:

npm install -g mapnik

Quick rendering test

To see if things are working try rendering a world map with the sample data

From the source checkout root do:

export NODE_PATH=./lib
./examples/simple/render.js ./examples/stylesheet.xml map.png

Using node-mapnik from your node app

To require node-mapnik as a depedency of another package put in your package.json:

"dependencies"  : { "mapnik":"0.6.x" }


See the 'examples/' folder for more usage examples.

For some of the tests you will need:

npm install express
npm install generic-pool
npm install get


To run the expresso tests first install expresso.

npm install expresso

Then run:

make test


BSD, see LICENSE.txt

Something went wrong with that request. Please try again.