sugo-endpoint-file

1.0.8 • Public • Published

sugo-endpoint-file

Build Status npm Version JS Standard

Endpoint to handle files

Requirements

Node.js NPM

Installation

$ npm install sugo-endpoint-file --save

Usage

Create an instance and apply to sg-server (or sugo-cloud)

/** This is an example to use sugo-endpoint-file */
 
'use strict'
 
const sgServer = require('sg-server')
 
const server = sgServer({
  middlewares: [
    /* ... */
  ],
  endpoints: {
    '/api/my-docs/:filename': require('sugo-endpoint-file')(
      'var/my-docs/', // Directory path to save files
      {
        // Options
      })
  }
})
 
server.listen(3000)
 
 

Then call the api from agent script.

'use strict'
 
const sugoAgentFile = require('sugo-agent-file')
const co = require('co')
 
co(function * () {
  let agent = sugoAgentFile('http://my-sever.com/files')
 
  // Check if server available
  {
    let ok = yield agent.knock() // Send HTTP HEAD request.
    /* ... */
  }
 
  // Access dynamic files
  {
    // Write
    yield agent.write('my-text-01.txt', 'This is the text.')
    // Read
    let content = yield agent.read('my-text-01.txt')
    console.log(content)
    /* ... */
    // Check
    let exists = yield agent.exists('my-text-01.text')
    if (exists) {
      // Delete
      yield agent.delete('my-text-01.txt')
    }
  }
}).catch((err) => console.error(err))
 

Signature

sugoEndpointFile(dirname, options) -> function

Endpoint to handle files

Args
Name Type Default Description
dirname string Directory name of files path
options object Optional settings.

License

This software is released under the Apache-2.0 License.

Links

Readme

Keywords

Package Sidebar

Install

npm i sugo-endpoint-file

Weekly Downloads

0

Version

1.0.8

License

Apache-2.0

Last publish

Collaborators

  • realglobe