requestjs

Node.JS Request - Invalid URI “/”

微笑、不失礼 提交于 2019-12-06 20:26:05
问题 I'm using request in my app to send a POST request over HTTPS with Client Authentication. Request always throws an error Error: Invalid URI "/" and I couldn't do anything to solve it. I've tried used url.parse instead of passing a string but it's still the same. request.post({ uri: 'https://localhost:5000', key: credentials.key, ca: credentials.ca, cert: credentials.cert, passphrase: credentials.passphrase, rejectUnauthorized: false }, { form: { data: payload }}); 回答1: Turns out it was caused

stream response from nodejs request to s3

爷,独闯天下 提交于 2019-12-05 02:39:29
How do you use request to download contents of a file and directly stream it up to s3 using the aws-sdk for node? The code below gives me Object #<Request> has no method 'read' which makes it seem like request does not return a readable stream... var req = require('request'); var s3 = new AWS.S3({params: {Bucket: myBucket, Key: s3Key}}); var imageStream = req.get(url) .on('response', function (response) { if (200 == response.statusCode) { //imageStream should be read()able by now right? s3.upload({Body: imageStream, ACL: "public-read", CacheControl: 5184000}, function (err, data) { //2 months

What is the proper way to loop through an array in an EJS template after an AJAX Call (using ExpressJS)?

萝らか妹 提交于 2019-12-05 00:15:22
So I am trying to loop through an array of objects that I got from an http call using to my internal API using the request module/package. So far, I am able to get my data back from the API and DISPLAY the full object on my page. I would like to display it on my page and loop through it using the EJS templating system. I know I can use AngularJS for frontend stuff, but I would like to see how far I can go with only server-side. So below is my code: server.js // Prepend /api to my apiRoutes app.use('/api', require('./app/api')); api.js var Report = require('./models/report'); var express =

NodeJS request multiple api endpoints

寵の児 提交于 2019-12-04 08:24:20
问题 Ok so I am trying to make two or more requests to API endpoints using the request module. I am rendering a HTML file and passing the returned JSON to a handlebars template using the below code: res.render('list.html', { title: 'List', data: returnedJSON } I can then iterate over this JSON within my handlebars template fairly easily. The problem I have, is that I am now needing to use multiple data sources where a category list will be built from a categories JSON response and a Staff list

NodeJS request multiple api endpoints

北战南征 提交于 2019-12-02 21:28:36
Ok so I am trying to make two or more requests to API endpoints using the request module. I am rendering a HTML file and passing the returned JSON to a handlebars template using the below code: res.render('list.html', { title: 'List', data: returnedJSON } I can then iterate over this JSON within my handlebars template fairly easily. The problem I have, is that I am now needing to use multiple data sources where a category list will be built from a categories JSON response and a Staff list from a staff JSON response. I would like a simple solution where I can do this, but expand it to use any

Getting binary content in Node.js using request

吃可爱长大的小学妹 提交于 2019-11-26 11:40:30
I was trying to GET a binary data using request , and had something like: var requestSettings = { method: 'GET', url: url, }; request(requestSettings, function(error, response, body) { // Use body as a binary Buffer } But body was always a few bytes different from expected. After further investigation I found out that request assumed body is string and replaced all non-unicode bytes. I tried to add encoding: 'binary' to requestSettings but it didn't help. How can I get the binary data? OK, after a lot of digging, I found out that requestSettings should have: encoding: null And then body will