Created
March 6, 2017 13:30
-
-
Save sebcode/9691783b1ddbb953939fa1b1ca60ef80 to your computer and use it in GitHub Desktop.
upload file with nodejs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs') | |
const http = require('http') | |
const uploadFile = 'uploadMe.txt' | |
const req = http.request({ | |
hostname: 'localhost', | |
port: 8080, | |
path: '/uploadtest', | |
method: 'PUT', | |
headers: { | |
'Content-Type': 'text/plain' | |
} | |
}, response => { | |
console.log(response.statusCode) | |
let data = '' | |
response.addListener('data', chunk => { | |
data += chunk | |
}) | |
response.addListener('end', () => { | |
console.log(data) | |
}) | |
}) | |
fs.createReadStream(uploadFile).pipe(req) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment