Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kathan/send-file
https://github.com/kathan/send-file
Last synced: 10 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/kathan/send-file
- Owner: kathan
- Created: 2017-09-03T15:34:47.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-05T16:23:49.000Z (over 6 years ago)
- Last Synced: 2024-10-07T12:24:30.734Z (about 1 month ago)
- Language: JavaScript
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# send-file
A Javascript module that simplifies sending files over HTTP ports.## Usage:
Create a server...
```js
const path = require('path');
const bodyParser = require('body-parser');
const express = require('express');
const fileUpload = require('express-fileupload');
const app = express();
const port = 4536;//==== Start Server ====
app.use(bodyParser.urlencoded({ extended: true }));
app.use(fileUpload());
app.post('*', (req, res) => {
console.log({file_name: req.files.file.name, data: req.files.file.data.toString()});
res.send('Success!');
});var server = app.listen(port, () => {
console.log(`Test app listening on port ${port}!`);
});
```
...then send a file!
```js
const sendFile = require('send-file');
const port = 4536;//==== Send File ====
sendFile(`http://localhost:${port}`, path.resolve(__dirname, 'test.file'), (err, result, reply)=>{
if(result){
console.log('Success!');
}else{
console.log('Error!', reply.statusCode);
}
});
```