node-share-folder
API and CLI application to run a REST host for sharing files and folders, written for Node.js 7+.
Install
As command line tool
npm install -g share-folder
As module
npm install --save share-folder
Usage
Command line
Share current folder:
share-folder
Show help:
share-folder --?
Share custom folder:
share-folder /path/to/folder/to/share
Run in SSL mode:
share-folder --cert=/path/to/ca/file --key=/path/to/key/file
Define username and password:
share-folder --user=mkloubert --password=P@ssword123!
Allow clients to write:
share-folder --can-write
Upload a file:
share-folder --upload /path/to/file/on/remote.txt < ./file-to-upload.txt
Download a file:
share-folder --download /path/to/file/on/remote.txt > ./downloaded-file.txt
Remove a file or folder:
share-folder --delete /path/to/file/or/folder/on/remote
Module
Complete documentation about the classes, interfaces and functions can be found here.
Run host
; ; await HOST.start;
Use client
;; ; // list directory;for of LIST // upload a fileawait CLIENT.upload'/path/to/file/on/remote.txt', fs.readFileSync'/path/of/file/to/upload'; // download filefs.writeFileSync '/path/to/downloaded/file.txt', await CLIENT.download'/path/to/file/on/remote.txt'; // delete file or folderawait CLIENT.remove'/path/to/file/or/folder/on/remote';
API
[DELETE] /path/to/file/or/folder/to/delete
Deletes a file or folder.
Example:
DELETE /my-file-or-folder
Possible respose:
HTTP/1.1 200 OKConnection: closeContent-Length: 114Content-Type: application/json; charset=utf8Date: Tue, 15 May 2018 19:25:19 GMTETag: W/"72-oPrCQJagCLUSh2PmGv+W7S+xo4M"X-Powered-By: node-share-folder (Express)X-Tm-Mk: 1979-09-05T23:09:00.000Z { "ctime": "2018-05-15T19:11:17.082Z", "mtime": "2018-05-15T19:11:17.082Z", "name": "my-file-or-folder", "size": 0, "type": 1}
[GET] /path/to/file/or/folder
List a directory
Example:
GET /
Possible respose:
HTTP/1.1 200 OKConnection: closeContent-Length: 218Content-Type: application/json; charset=utf8Date: Tue, 15 May 2018 17:20:59 GMTETag: W/"da-sIP9lRV14VgW0g/mFthDumv5hqE"X-Powered-By: node-share-folder (Express)X-Share-Folder-Type: dX-Tm-Mk: 1979-09-05T23:09:00.000Z [ { "ctime": "2018-05-15T03:20:43.536Z", "mtime": "2018-05-15T03:20:43.536Z", "name": "test-folder", "size": 0, "type": 1 }, { "ctime": "2018-05-15T17:13:40.979Z", "mtime": "2018-05-15T17:13:40.979Z", "name": "test-file.txt", "size": 22, "type": 2 }]
Get content of a file
Example:
GET /test-file.txt
Possible respose:
HTTP/1.1 200 OKConnection: closeContent-Disposition: attachment; filename="test-file.txt"Content-Length: 1706Content-Type: text/plainDate: Tue, 15 May 2018 17:22:38 GMTETag: W/"16-MKQSnrz7Udk6d5pTlq5C66K847M"X-Powered-By: node-share-folder (Express)X-Share-Folder-Type: fX-Tm-Mk: 1979-09-05T23:09:00.000Z Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
Get info of a file or folder
GET /test-file.txt?info=1
Possible response:
HTTP/1.1 200 OKConnection: closeContent-Length: 112Content-Type: application/json; charset=utf8Date: Tue, 15 May 2018 17:38:37 GMTETag: W/"70-z+vwPpHUvk692rkWEZzIZHAhJU4"X-Powered-By: node-share-folder (Express)X-Tm-Mk: 1979-09-05T23:09:00.000Z { "ctime": "2018-05-15T17:24:07.094Z", "mtime": "2018-05-15T17:24:07.094Z", "name": "test.txt", "size": 1706, "type": 2}
[POST] /path/to/folder/to/create
Creates a new directory.
POST /my-new-folder
Possible response:
HTTP/1.1 200 OKConnection: closeContent-Length: 101Content-Type: application/json; charset=utf8Date: Tue, 15 May 2018 19:11:17 GMTETag: W/"65-A0B7XUVLv2NMnQ0vYHwV2lBVbgo"X-Powered-By: node-share-folder (Express)X-Tm-Mk: 1979-09-05T23:09:00.000Z { "ctime": "2018-05-15T19:11:17.082Z", "mtime": "2018-05-15T19:11:17.082Z", "name": "my-new-folder", "size": 0, "type": 1}
[PUT] /path/to/file
Writes to a file.
PUT /my-file Lorem ispum
Possible response:
HTTP/1.1 200 OKConnection: closeContent-Length: 102Content-Type: application/json; charset=utf8Date: Tue, 15 May 2018 19:14:11 GMTETag: W/"66-b5W/DNIHdZfEUzg6h+WRj/oDsVA"X-Powered-By: node-share-folder (Express)X-Tm-Mk: 1979-09-05T23:09:00.000Z { "ctime": "2018-05-15T19:14:11.079Z", "mtime": "2018-05-15T19:14:11.079Z", "name": "my-file", "size": 11, "type": 2}
Support and contribute
If you like the module, you can support the project by sending a donation via PayPal to me.
To contribute, you can open an issue and/or fork this repository.
To work with the code:
- clone this repository
- create and change to a new branch, like
git checkout -b my_new_feature
- run
npm install
from your project folder - open that project folder in Visual Studio Code
- now you can edit and debug there
- commit your changes to your new branch and sync it with your forked GitHub repo
- make a pull request
Related projects
node-enumerable
node-enumerable is a LINQ implementation for JavaScript, which runs in Node.js and browsers.