Skip to content

Instantly share code, notes, and snippets.

@sebcode
Created March 6, 2017 13:30
Show Gist options
  • Save sebcode/9691783b1ddbb953939fa1b1ca60ef80 to your computer and use it in GitHub Desktop.
Save sebcode/9691783b1ddbb953939fa1b1ca60ef80 to your computer and use it in GitHub Desktop.
upload file with nodejs
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