restify

Node.js EventEmitter error

萝らか妹 提交于 2019-12-02 12:27:44
I have an error when trying to inherit EvenEmitter /* Consumer.js */ var EventEmitter = require('events').EventEmitter; var util = require('util'); var Consumer = function() {}; Consumer.prototype = { // ... functions ... findById: function(id) { this.emit('done', this); } }; util.inherits(Consumer, EventEmitter); module.exports = Consumer; /* index.js */ var consumer = new Consumer(); consumer.on('done', function(result) { console.log(result); }).findById("50ac3d1281abba5454000001"); /* ERROR CODE */ {"code":"InternalError","message":"Object [object Object] has no method 'findById'"} I've

Node.js stream upload directly to Google Cloud Storage

天大地大妈咪最大 提交于 2019-12-01 05:31:11
问题 I have a Node.js app running on a Google Compute VM instance that receives file uploads directly from POST requests (not via the browser) and streams the incoming data to Google Cloud Storage (GCS). I'm using Restify b/c I don't need the extra functionality of Express and because it makes it easy to stream the incoming data. I create a random filename for the file, take the incoming req and toss it to a neat little Node wrapper for GCS (found here: https://github.com/bsphere/node-gcs) which

RESTify on Node.js POST body / json

蹲街弑〆低调 提交于 2019-12-01 03:35:53
I am in need of help. I am POSTing json data to my node server. The node server is using RESTify for its API. I am having trouble getting req.body.name from the body of the posted data. The posted data contains a json body. In it i have keys such as name, date, address, email, etc. I want to get the name out of the json body. I am trying to do req.body.name but it is not working. I have also included server.use(restify.bodyParser()); and it is not working. I am able to req.params.name and assign a value. But if I POST json data like: {'food': 'ice cream', 'drink' : 'coke'} , I am getting

How to parse/read multiple parameters with restify framework for Node.JS

萝らか妹 提交于 2019-11-29 02:54:51
Scenario : We developer are trying to replace a web service (written in C#.Net) with Node.JS Restful API. Issue : Now we need to handle the incoming request as is (we don't have control over it). So the following is the format of the incoming URL: http://www.website.com/Service.aspx?UID=Trans001&FacebookID=ae67ea324&GetDetailType=FULL I am able to handle the URL like: http://www.website.com/service/Trans001/ae67ea324/FULL I can parse/read the parameter from the above URL Code: var server = require('restify').createServer(); function respond(req, res, next) { console.log("req.params.UID:" + req

How to parse/read multiple parameters with restify framework for Node.JS

一笑奈何 提交于 2019-11-29 02:53:06
Scenario : We developer are trying to replace a web service (written in C#.Net) with Node.JS Restful API. Issue : Now we need to handle the incoming request as is (we don't have control over it). So the following is the format of the incoming URL: http://www.website.com/Service.aspx?UID=Trans001&FacebookID=ae67ea324&GetDetailType=FULL I am able to handle the URL like: http://www.website.com/service/Trans001/ae67ea324/FULL I can parse/read the parameter from the above URL Code: var server = require('restify').createServer(); function respond(req, res, next) { console.log("req.params.UID:" + req

Application 'appname' failed to start (port 8080 not available) on open shift node app

时间秒杀一切 提交于 2019-11-28 08:17:51
I have written a node restify server in coffee and I can't seem to get it running. While deploying I get the following error: Waiting for application port (8080) become available ... after which I do get the following error Application 'appname' failed to start (port 8080 not available) If coffeescript seems to be the problem is there a work around it. I would not want to change back to js. My server code is: restify = require 'restify' Bunyan = require 'bunyan' server = restify.createServer name: 'APPNAME' version: '0.0.1' log: Bunyan.createLogger name: 'api' serializers: req: ()-> return

How can I support cors when using restify

Deadly 提交于 2019-11-28 06:43:18
I have a REST api created with the restify module and I want to allow cross-origin resource sharing. What is the best way to do it? You have to set the server up to set cross origin headers. Not sure if there is a built in use function or not, so I wrote my own. server.use( function crossOrigin(req,res,next){ res.header("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Allow-Headers", "X-Requested-With"); return next(); } ); I found this from this tutorial. http://backbonetutorials.com/nodejs-restify-mongodb-mongoose/ Jean-Michel Trayaud The latest version of Restify provides a

How to parse/read multiple parameters with restify framework for Node.JS

♀尐吖头ヾ 提交于 2019-11-27 17:11:31
问题 Scenario : We developer are trying to replace a web service (written in C#.Net) with Node.JS Restful API. Issue : Now we need to handle the incoming request as is (we don't have control over it). So the following is the format of the incoming URL: http://www.website.com/Service.aspx?UID=Trans001&FacebookID=ae67ea324&GetDetailType=FULL I am able to handle the URL like: http://www.website.com/service/Trans001/ae67ea324/FULL I can parse/read the parameter from the above URL Code: var server =

Error: getaddrinfo ENOTFOUND in nodejs for get call

﹥>﹥吖頭↗ 提交于 2019-11-27 07:12:39
I am running a web server on node the code for which is given below var restify = require('restify'); var server = restify.createServer(); var quotes = [ { author : 'Audrey Hepburn', text : "Nothing is impossible, the word itself says 'I'm possible'!"}, { author : 'Walt Disney', text : "You may not realize it when it happens, but a kick in the teeth may be the best thing in the world for you"}, { author : 'Unknown', text : "Even the greatest was once a beginner. Don't be afraid to take that first step."}, { author : 'Neale Donald Walsch', text : "You are afraid to die, and you're afraid to

Difference between response.send and response.write in node js

佐手、 提交于 2019-11-27 06:52:23
I have written a small API which uses the Node js "restify" framework. This API receives a request (actually anything after "/") and then send that request to another server. Get the response back from server and passes the response back to original source of request. For this API I am using both restify server and client. Below is that API code for better understanding. var apiServer = require('apiServer'); apiServer.start(); var restify = require('restify'); var assert = require('assert'); function onRequest(request, response, next) { var client = restify.createStringClient({ url: 'http:/