# ldnode [](https://travis-ci.org/linkeddata/ldnode) [](https://npm.im/ldnode) [](http://gitter.im/linkeddata/ldnode) Linked Data Platform server based on [rdflib.js](https://github.com/linkeddata/rdflib.js) and [node.js](https://nodejs.org/). This is all you need to run distributed linked data apps on top of the file system. You can run ldnode as a [command-line tool](https://github.com/linkeddata/ldnode/blob/master/README.md#command-line-tool) or as a [library](https://github.com/linkeddata/ldnode/blob/master/README.md#library) for your Nodejs/Express app. ## Features - [x] GET, PUT, POST and PATCH support - [x] Proxy for cross-site data access - [x] Access control using RDF ACLs - [x] WebID+TLS Authentication - [x] Mount as express' router - [x] Command line tool - [x] Real-time live updates (using websokets) ## Command line tool npm install -g ldnode The command line tool has the following options ``` Usage: ldnode [options] Options: -v, --verbose Print the logs to console --version Print current ldnode version -m, --mount Where to mount Linked Data Platform (default: '/') -r, --root Root location on the filesystem to serve resources -p, --port Port to use -c, --cache Set cache time (in seconds), 0 for no cache -K, --key Path to the ssl key -C, --cert Path to the ssl cert --webid Enable WebID+TLS authentication -s, --secret HTTP Session secret key (e.g. "your secret phrase") -P, --proxy Use a proxy on example.tld/proxyPath --no-live Disable live support through WebSockets -sA, --suffix-acl Suffix for acl files (default: '.acl') -sM, --suffix-meta Suffix for metadata files (default: '.meta') -sC, --suffix-changes Suffix for acl files (default: '.changes') -sE, --suffix-sse Suffix for SSE files (default: '.events') ``` For example, to start your own server using the current folder: ```bash $ ldnode --webid --port 443 --cert /path/to/cert --key /path/to/key ``` ## Library ### Install ``` npm install ``` ### Usage The library provides two APIs: - `ldnode.createServer(settings)`: starts a ready to use [Express](http://expressjs.com) app. - `lnode(settings)`: creates an [Express](http://expressjs.com) that you can mount in your existing express app. In case the `settings` is not passed, then it will start with the following default settings. ```javascript { cache: 0, // Set cache time (in seconds), 0 for no cache live: true, // Enable live support through WebSockets root: './', // Root location on the filesystem to serve resources secret: 'node-ldp', // Express Session secret key cert: false, // Path to the ssl cert key: false, // Path to the ssl key mount: '/', // Where to mount Linked Data Platform webid: false, // Enable WebID+TLS authentication suffixAcl: '.acl', // Suffix for acl files suffixChanges: '.changes', // Suffix for acl files suffixSSE: '.events', // Suffix for SSE files proxy: false, // Where to mount the proxy errorHandler: false, // function(err, req, res, next) to have a custom error handler errorPages: false // specify a path where the error pages are } ``` Have a look at the following examples or in the [`examples/`](https://github.com/linkeddata/ldnode/tree/master/examples) folder for more complex ones ##### Simple You can create an ldnode server ready to use using `ldnode.createServer(opts)` ```javascript var ldnode = require('ldnode') var ldp = ldnode.createServer({ key: '/path/to/sslKey.pem', cert: '/path/to/sslCert.pem', webid: true }) ldp.listen(3000, function() { // Started Linked Data Platform }) ``` ##### Advanced You can integrate ldnode in your existing express app, by mounting the ldnode app on a specific path using `lnode(opts)`. ```javascript var ldnode = require('ldnode') var app = require('express')() app.use('/test', ldnode(yourSettings)) app.listen(3000, function() { // Started Express app with ldp on '/test' }) ... ``` ##### Logs Run your app with the `DEBUG` variable set: ```bash $ DEBUG="ldnode:*" node app.js ``` ## Tests ```bash $ npm test # running the tests with logs $ DEBUG="ldnode:*" npm test ``` In order to test a single component, you can run ```javascript npm run test-(acl|formats|params|patch) ``` ## Contributing `ldnode` is only possible due to the excellent work of the following contributors:
| Tim Berners-Lee | GitHub/timbl | Twitter/@timberners_lee | webid |
|---|---|---|---|
| Nicola Greco | GitHub/nicola | Twitter/@nicolagreco | webid |
| Martin Martinez Rivera | GitHub/martinmr | ||
| Andrei Sambra | GitHub/deiu | Twitter/@deiu | webid |