Git Product home page Git Product logo

nexus-server's Introduction

Nexus

Standard - JavaScript Style Guide

Nexus is a simple remote file storage server over HTTP. Easily create, read and update files remotely, using only HTTP. With an easy to use HTTP API and node.js client, it's fast to set up and use.

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.

Features

  • Simple to use HTTP API
    • To download a file, simply make a request: GET /my/resource.json
    • To upload a file, make another simple request: PUT /my/resource.json (POST works too)
  • The given path is the resource path
    • Extensions are optional, but a resource will always be a file
    • E.g. /resource, /resource.json, /dir/subdir/another/resource
  • Support for read (r), write (w) and append (a) modes (may depend on the store used)
  • Abstracts file handling, making it possible to use multiple types of stores

Roadmap

Soon

  • Support partial content and Range headers

Longer

  • Support for authentication
  • Maybe look into making core functionality transport-independent
    • WebSocket support would make a nice addition
    • Vanilla TCP might be fun too

Install

npm install nexus-server

Stores

In order to get Nexus running, you need a store. As the name suggests, a store is where your files will be... stored. Nexus abstracts file handling, providing a lot of flexibility in what storage back-ends to use.

By default Nexus comes bundled with FileStore, a store which uses the local file system to store resources. Because the store is so important, you'll have to set one manually.

It's simple to make your own store, as they use streams. Any object which has the methods createReadStream(resource, mode) and createWriteStream(resource, mode) and which return a Promise that resolves in the appropriate stream will work fine. For an example, see FileStore.js.

Setting up a server

A few lines of code say more than a thousand words.

const path = require('path')
const Nexus = require('nexus-server')

const server = new Nexus.Server({
  // FileStore requires an absolute path!
  store: new Nexus.FileStore(path.resolve(process.cwd(), './resources'))
})

server.listen().then(() => {
  // Get the address from the underlying http.Server
  const address = server.server.address()
  console.log(`server listening on ${address.address}:${address.port}`)
}).catch(err => {
  console.error(`error starting server: ${err.message}`)
})

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 Nexus uses http.Server, so all options that can be provided to https.createServer([options]) will be valid for use.

const server = new Nexus.Server({
  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.

nexus-server's People

Contributors

michielvdvelde avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.