nexus-client-http

0.0.1-alpha2 • Public • Published

Nexus client for node.js

Standard - JavaScript Style Guide

Node.js HTTP client for Nexus, a simple HTTP file storage server.

The client provides a streams-compatible interface. It's a thin-veiled semantic wrapper that makes it as simple to work with remote files as it is with local files.

Nexus is currently an alpha version. Use at your own risk.

Important: The version you see here MAY NOT be the one currently published on npm! To check the latest published version, look at the package on npm.

Documentation is sparse at the moment, I will write some more later. In the mean time take a look at the source code if you're interested.

Install

npm install nexus-client-http

Examples

These trivial examples are really as simple as they look!

Getting a new client

const Client = require('nexus-client-http')

const client = new Client({
  // These options are given to http.request
  hostname: 'localhost', // this is the default host name
  port: 6607 // this is the default port
})

Read example

Loads a remote resource and pipes it to a local file. Also see example-read.js.

const fs = require('fs')

const remote = client.createReadStream('/resource.json')
const local = fs.createWriteStream('./resource.json')

local.on('end', () => {
  console.log('read ended!')
})

// Pipe the remote stream to the local stream
remote.pipe(local)

Write example

Writes the contents of a local file to a remote resource. Also see example-write.js.

const fs = require('fs')

const local = fs.createReadStream('./resource.json')
const remote = client.createWriteStream('/resource.json')

remote.on('end', () => {
  console.log('write ended!')
})

// Pipe the local stream to the remote stream
local.stream(remote)

Enabling SSL

By setting options.secure to true and providing the appropriate keys and/or certificates in the options object, HTTPS will be enabled and your connection will be secure.

Note that this client uses http(s).request, so all options that can be provided there will be valid.

const client = new Client({
  secure: true,
  key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
  cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem')
})

Standard - JavaScript Style Guide

License

Copyright 2017 Michiel van der Velde.

This software is licensed under the MIT License.

Package Sidebar

Install

npm i nexus-client-http

Weekly Downloads

0

Version

0.0.1-alpha2

License

MIT

Last publish

Collaborators

  • michielvdvelde