node-localwiki-client

A node.js wrapper library to the localwiki api.

npm install node-localwiki-client
24 downloads in the last month

node-localwiki-client

A simple node.js wrapper for the localwiki api.

Installation:

npm install node-localwiki-client

Examples:

Require the module:

var LocalWikiClient = require('node-localwiki-client')

Initialize with at least the localwiki url:

var wiki = new LocalWikiClient({
  url: 'YOUR_LOCALWIKI_URL' // like http://seattlewiki.net or https://sfwiki.org

  // user and apikey not required for get requests
  user: process.env.LOCALWIKI_USER,
  apikey: process.env.LOCALWIKI_API_KEY
});

create a page named Waterside Park

wiki.create({
  resource_type: LocalWikiClient.Type.PAGE,
  data: {
    'name': "Waterside Park",
    'content': "A simple test page."
  }
}, function(error, resource) {
  console.log("Created new page", resource.identifier);
});

get a resource

wiki.fetch({ identifier: 'WatersidePark' }, function(error, resource) {
  console.log("page data: ", resource.data.content);
});

update a page

wiki.fetch({ identifier: 'WatersidePark' }, function(error, resource) {
  resource.data.content += "<br /> Updated at " + new Date();
  resource.update(function() {
    console.log("Success");
  });
});

delete a page

resource.delete(function() {
  console.log("resource deleted.");
});

list multiple resources

wiki.list({
  resource_type: LocalWikiClient.Type.PAGE,
  filters: {
    limit: 5
  },
  function(error, items) {
    console.log("found " + items.length + " matching pages.")
  }
})
npm loves you