Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# express-rest-file-server
[![travis-ci](https://travis-ci.org/bitIO/express-rest-file-server.svg?branch=master)](https://travis-ci.org/bitIO/express-rest-file-server)
[![Build Status](https://travis-ci.org/bitIO/express-rest-file-server.svg?branch=master)](https://travis-ci.org/bitIO/express-rest-file-server)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
[![Version npm](https://img.shields.io/npm/v/express-rest-file-server.svg?style=flat-square)](https://www.npmjs.com/package/express-rest-file-server)
[![npm Downloads](https://img.shields.io/npm/dm/express-rest-file-server.svg?style=flat-square)](https://npmcharts.com/compare/express-rest-file-server?minimal=true)

[![NPM](https://nodei.co/npm/express-rest-file-server.png?downloads=true&downloadRank=true)](https://nodei.co/npm/express-rest-file-server/)

An express based application, inspired by [mock-file-server](https://github.com/betajs/mock-file-server), to be used as a CRUD file server storing content in the memory (temporal) or in the disk (permanent) of the server.

Expand Down Expand Up @@ -29,3 +33,32 @@ npx express-rest-file-server
* storageType: can be `memory` or `disk` (defaults to memory)
* storagePath: where to store the files if storage is set to `disk` (defaults to `/tmp`)

## Routes

### POST /files

Uploads a file to the store with its original name

### POST /files/:filename

Uploads a file to the store with a custom name (:filename)

### POST /files/chunk/:filename

Uploads a chuck of a file to the store with a custom name (:filename)

### POST /files/assemble/:filename

_Builds_ a file from its chunks

### GET /files/:filename

Retrieve a file by its name

### GET /files/:filename/size

Retrieve a file size by its name

### DELETE /files/:filename

Remove a file by its name
211 changes: 211 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"commit": "git-cz",
"prebuild": "rimraf lib",
"prepublishOnly": "pkg-ok",
"start": "babel-node src/index.js",
"start": "babel-node src/index.js -v",
"start:disk": "babel-node src/index.js --storageType=disk",
"start:prod": "node lib/index.js",
"test": "echo \"Error: no test specified\" && exit 0",
Expand All @@ -48,6 +48,7 @@
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-stage-0": "^6.24.1",
"commitizen": "^2.9.6",
"cz-conventional-changelog": "^2.1.0",
"eslint": "^4.19.1",
Expand All @@ -60,7 +61,10 @@
},
"babel": {
"plugins": [],
"presets": "env"
"presets": [
"env",
"stage-0"
]
},
"eslintConfig": {
"extends": "airbnb-base",
Expand Down
22 changes: 19 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
import nodegetopt from 'node-getopt';
import logger, { setLogLevel } from './log';
import server from './server';
import pkg from '../package.json';

const opt = nodegetopt.create([
['p', 'port=PORT', 'server port (default 5000)'],
['', 'chunknumber=CHUNKNUMBER', "chunk number parameter (default 'chunknumber')"],
['', 'totalsize=TOTALSIZE', "total size parameter (default 'totalsize')"],
['', 'storageType=TYPE', "disk or memory (default 'memory')"],
['', 'storagePath=PATH', "where to save files (default '/tmp')"],
['', 'route=flies', "the API starting path (default '/files')"],
['v', 'verbose', 'change log level to lowest'],
]).bindHelp().parseSystem().options;

logger.info('================================');
logger.info('>>> Express REST file server');
logger.info(`>>> version: ${pkg.version}`);
logger.info('================================');

if (opt.verbose) {
setLogLevel('silly');
logger.debug('Command line options', opt);
}

server.run({
chunkNumber: opt.chunknumber,
port: (opt.port || process.env.PORT || 5000),
chunkNumber: opt.chunknumber,
totalSize: opt.totalsize,
storage: {
type: opt.storageType,
path: opt.storagePath,
type: (opt.storageType || 'memory'),
path: (opt.storageType === 'disk' && opt.storagePath ? opt.storagePath : '/tmp'),
},
route: (opt.route || 'files'),
verbose: (!!opt.verbose),
});
Loading