spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » NODE JS » Page 1
In nodejs trying to get http-proxy to forward requests passing through query string parameters
I got this working by changing the req.url to contain the querystring params and pass the hostname only to the apiProxy.web target parameter: app.use('/*', function(req, res) { var proxiedUrl = req.baseUrl; var url = require('url'); var url_parts = url.parse(req.url, true); if (url_parts.search !== null) { proxiedUrl += url_parts.search; } req.url = proxiedUrl;

Categories : Node Js

Cassandra requesting data from a node which is down?
The default load balancing policy in the DataStax Node.js Driver for Cassandra is TokenAwarePolicy with DCAwareRoundRobinPolicy as child policy. The DCAwareRoundRobinPolicy is set to use 0 remote nodes by default. You can change it to use 1 node of each remote datacenter, if the local nodes fail. var localDc = "east1"; var remoteNodes = 1; var options = { policies: {loadBalancing: new DCAware

Categories : Node Js

Node.js, socket.io and IIS 7
From what I've read IIS 8 is the first version of IIS with WebSockets, until then longpolling is used. As for the output in your comment, you will see that because the Socket.io client is going to attempt to establish a connection by default with longpolling and then will attempt to upgrade the connection to WebSockets, unless you explicitly specify that it shouldn't. This can be done in the opti

Categories : Node Js

Result of socket.io request in IE 9 is Pending
If you're doing long polling as your socket transport (xhr, jsonp, etc...) having pending http requests is expected. The socket client should open an http GET to the server and the server should keep it open until there is data for the socket or the http interval expires. When either of those cases happen the client re-opens a GET and starts listening again. So in practice there should always be o

Categories : Node Js

Pattern for if(require.main) that works on Azure's iisnode
I only found a hackish solution to this problem, which basically detects whether I am running iisnode or not: var onIISNode = require.main.filename.match(/iisnode/); if(onIISNode || require.main === module){ ... } Improvements are welcome ... especially ones actually using the official Azure API for NodeJS

Categories : Node Js

using flock inside crontab with node script throws an error
My password has a '%' in it. So I had to remove the single quotes and pass the argument as: */5 * * * * flock -n /tmp/reddit.lock /usr/local/bin/node /home/user/projects/reddit/index.js -u me -p pass\%foo -vvv This took me awhile to find the problem, hopefully it helps someone else.

Categories : Node Js

use GET method in node js request?
An HTTP GET request cannot have a request body. $_GET parses parameters from the query string. The headers Content-Lengthand Content-Type do not make sense for a GET request as they apply to the body of the request, which GET cannot have. You need to use the qs option instead of body. req({ uri: 'http://localhost:8080/sms/index.php', qs: form, method: 'GET' }, function (err, res, b

Categories : Node Js

Is there any template engines in node.js like erb
EJS is the closest, here are some links to help you: Scotch Tutorial Homepage for EJS Npm package

Categories : Node Js

Can't run express server on hostmonster
The outside world need access to your express application that is running on your Hostmonster account and in particular on port 3000. Create a DNS entry for node.domain.com pointing to your server Make sure that port 3000 is accessible for all incoming requests - this is usually done on the firewall The cause of your error is that curl is being blocked from accessing your express application r

Categories : Node Js

How do I use npm to install and run packages?
If you want to use jsonlint from the command line anywhere on your system you'll need to install globally. $ sudo npm install -g jsonlint Without the -g flag it will install in the current project directory.

Categories : Node Js

Use JavaScript libraries inside of Gruntfile
Doesn't look like you required underscore anywhere, unless you're not showing the whole file. Any file in which you want to use underscore you need to do: var _ = require('underscore'); before making use of _. Oh, and of course you need to npm install underscore --save in the folder the gruntfile is in as well, to have the library there.

Categories : Node Js

Strange behaviour of Mean.io on Azure VM‏
I have tried to dockerize all infrasctructure, in the same machine (a CoreOS vm on azure): 1 container with mean app, 1 container with MongoDB, the problem still persisted!!! finally, i have found the solution: keep the connection to MongoDB alive. i have modified the server.js file from the mean app in this mode: var options = { server: { socketOptions: { keepAlive: 1 } } }; va

Categories : Node Js

NodeJS getting stuck in callback
you should always return your callbacks to make sure that your function terminates correctly and returns the control to the calling context: Client.prototype.countActiveChatsRedis = function (userID, agentID, obj, callback) { var count = 0; pub.keys("widgetActive:" + userID + ":*", function(err, key) { if(err !== null) { console.log("Redis error..... --> " + err); return

Categories : Node Js

How to connect Mongoose in Bluemix
Can you try like below,it will remove the dependency to explicitly mentioning the mongodb version : /*var mongoUrl; */ var db; if (process.env.VCAP_SERVICES) { var env = JSON.parse(process.env.VCAP_SERVICES); for (var svcName in vcapServices) { if (svcName.match(/^mongo.*/)) { db = mongoose.createConnection(env['mongodb-2.2'][0].credential

Categories : Node Js

Error when using npm
I think the issue is due to the permissions. Try to change the permissions as followed : Unlock permissions in your home directory. sudo chown -R `whoami` ~/.npm If 1 does not work, get write permissions to the node_modules directory. sudo chown -R `whoami` /usr/local/lib/node_modules If you still face error, update permission of /usr/local. sudo chown -R `whoami` /usr/local Hope it help

Categories : Node Js

Designing nodejs expressjs mongodb Webserver flow for desktop, mobile native apps and oAuth functionality
As for the desktop vs. mobile issue you can take a look @ http://stackoverflow.com/a/3540295/358280 and http://stackoverflow.com/a/21758511/358280 And for the distinction between your jwt tokens and oauth i suggest you take a look at https://auth0.com/blog/2014/01/27/ten-things-you-should-know-about-tokens-and-cookies/#token-oauth (section 9).

Categories : Node Js

NVM - All The Packages I Installed with NPM Suddenly Stops Working
Nvm(nevermind). I got it working by setting the default to my node version by: nvm alias default v0.10.33 So everytime I open a new terminal, node and other command just works.

Categories : Node Js

can't npm install bcrypt in my docker image
Thanks to everyone whose advice in the comments and answers steered me to my conclusion. The issue was either some sort of corruption within my docker install, or some sort of incompatibility between dvm and fig, but I solved this problem as follows dvm down brew remove fig brew remove dvm brew remove docker brew cleanup --force -s rm -rf ~/VirtualBox VMs/boot2docker-vm brew install docker brew

Categories : Node Js

How do I customize nginx on AWS elastic beanstalk to loadbalance Meteor?
Have you checked out Meteor WebSocket handshake error 400 with nginx? I think their configuration might be a bit different from yours. I'm in the same boat as you, trying to get this exact same set up working.

Categories : Node Js

parsing data in Node.js
results is an array of objects! search('deadmau5', opts, function(err, results) { if(err) return console.log(err); results.forEach(function (result) { console.log(result.url); }); }); this code will iterate over your array and log the url-property of each object in your results-array! and as Seth mentioned, you are getting more than 3 searchresults!

Categories : Node Js

Add authentication provider to Azure Mobile Services Nodejs backend
There is a way to achieve the scenario, but it is not as turnkey as in the .NET backend. It requires some manual work to achieve. There is not a direct parallel to the LoginProvider, but if you have the ability to log users in and validate the tokens (say via an NPM module), then you could issue your own Mobile Services tokens. A team member wrote a blog post describing how to build your own Mobi

Categories : Node Js

node js callback ambiguity
You're not waiting for the asynchronous client.get() to finish before sending your response. Change your fetchFromDb() function to something like this: function fetchFromDb(name,res){ console.log("Key given : [" + name+"]"); client.get(name,function(err,data){ if(err) console.log("Error encountered!"); console.log("Value fetched ..." + data); res.jsonp({"result":

Categories : Node Js

can you use jade to only render the dynamic part of your html...and not mess with rest of your html
You can use Jade's compileClient function to create a function that will render predefined Jade code on the fly. (See the API reference.) So, if you create a Jade file with the dynamic HTML, and compile that for the client, you can then call that function at a later time, and insert the resulting HTML string to the DOM.

Categories : Node Js

What does mean brackets in: require("./config")[somevar]
config.js returns an object. module.exports = { "env" : "Hello World" }; Bracket notation is defined clearly in the specification.

Categories : Node Js

Overriding Relation Remote Method In Strongloop Loopback
I figured out that I can juse add a new remote method the normal way. loopback.remoteMethod( UserModel.prototype.getFollows, { description: 'Get the users who are followed by the user', accepts: [ {arg: 'page', type: 'Number', http: {source: 'query'}, required: true} ], returns: {arg: 'data

Categories : Node Js

Mongodb sort by either of two fields
Maybe something like this, 1 db.test.aggregate([ {$project: {name: 1, field1: 1, field2: 1}}, {$group: {_id: '$name', field_1: { $last: '$field1' }, field_2: { $last: '$field2' }}}, {$project: {name: 1, field_1: 1, field_2: 1, cmp: { $cmp: ['$field_2', '$field_1'] } }}, {$sort: { cmp: -1, field_1: -1, field_2: -1 }} ]) 2 db.test.aggregate([ {$project: {name: 1, field1: 1,

Categories : Node Js

Activate Node function on action
Triggering an action on click is something that front end usually needs to initiate. You would fire an Ajax request to one of your backend routes. Let's day you have a route like var successfulCalls = 0; app.get('/my-action', function(req, res) { // you can do your action here //like calling a database or something // then you need to, eventually, close the request. db.ge

Categories : Node Js

npm -v reports error when node.js has been installed
Following instructions work Below are the steps to install Node.js from source (OSX/linux) You may/should issue all these cmds as yourself NOT root (sudo) NOTE - this installs Node.js which gives you both node as well as npm, they come together per release. to start fresh remove prior node and npm installs as well as these : sudo mv ~/.npmrc ~/.npmrc_ignore sudo mv ~/.npm ~/.npm_ignor

Categories : Node Js

Automatic run gulp tasks via npm
Have I got a treat for you: I went ahead and made you a simple npm module to handle this. gulp-npm-script-sync Here is the gist of it: var file = fs.readFileSync(config.path || 'package.json', 'utf-8'); var pkg = JSON.parse(file); var tasks = gulp.tasks; pkg.scripts = pkg.scripts || {}; Object.keys(tasks).forEach(function (t) { pkg.scripts[t] = 'gulp '+tasks[t].name; }); The

Categories : Node Js

Node/Mongo unable to find by ObjectId
Same as in mongo shell, you need to compose a query object for find(). Here is the example: var mongodb = require('mongodb'); var MongoClient = mongodb.MongoClient; var ObjectId = mongodb.ObjectID; MongoClient.connect('mongodb://localhost:27017/test', function(err, db) { db.collection('people', function(err, collection) { collection.find({_id: new ObjectId('544d644cf6eea12336f5e0a1')}).toA

Categories : Node Js

MongooseJS populate using multiple target fields
I don´t know whether I understand this correctly, but it is in any way very clear what Mongoose is populating at any time. If you run Message.find().populate('sender recipient').exec(..), you get every document with sender and recipient being their respective MongoDB documents. If you run User.find().populate('messages').exec(..), you get an array of every message matching the ObjectId. By your

Categories : Node Js

Node.js Express - Specifying path to root of app
When using express, the path will be routed through one of your declared handlers or via the static module if you've set that up. Normally Express is configured to use static and to map it to your applications public folder. When using the express-generator that folder is located at <approot>/public/. So in order to access something like this: <head> <script type="text/javascri

Categories : Node Js

Node.js HTMLParser iterating more than one time
The data event may fire more than once while information is incoming. You need to store the incoming Buffer (i.e. chunk) into your own buffer and parse when the response is complete. That is why it is referred to as a chunk - it is partial data. var req = http.request(options, function(res) { res.setEncoding('utf8'); var content = ''; res.on('data', function (chunk) { content += chunk;

Categories : Node Js

Nodejs forked child process exits immediately with status code 8
SOLUTION : Incase someone else gets this issue. I managed to get around by having silent set to true. var testBot = childProcess.fork(require.resolve("./../../bots/testBot"),[],{silent:true});

Categories : Node Js

Asynchronous operation in router.use
Sure it will as long as you use next() properly Example: router.use('/', function(req, res, next) { somethingAsync(function(err, result) { if(err) return next(err); // Do whatever return next(); }); }); The router stack is called in the order routes are added to it. Calling next() calls the next route in the stack matching the provided path. Calling next(someError) calls the

Categories : Node Js

node tools for visual studio profiling: v8 log file was not saved, no data
Turns out it is not that difficult, similar to How to debug node.js application with Visual Studio 2013 and Node Tools NTVS . The profiling option needs to be set by hand. I suppose I will see that I change my application to use app.js for startup, since this seems to (right now) be more compatible with VS.

Categories : Node Js

Nodejs websocket communication with external system
Thanks for the hints. I ended with the following solution which does what I expect: var ws = require('ws'); var express = require('express'); var uuid = require('node-uuid'); var requests = {}; app = express(); var webSocket = new ws('ws://localhost:5000/'); webSocket.on('open', function () { console.log('Connected!'); }); webSocket.on('message', function (data, flags) { v

Categories : Node Js

How can I get the contents of a file of a git commit with the gift library?
Yes, it's a tree-ish ID, that is sha-1 of a given filesystem object, in case of a plain file, sha-1 of its content. To get an object at a given point of time, you should choose an appropriate commit first. Please note, that in a project there might be more than one commit at a given time with a file with a given name, because of possible branches. So you should choose a branch and then query that

Categories : Node Js

Node/Express server randomly skips requests for static files
This was apparently caused by a problem at the Digital Ocean datacenter, not related to my actions. I diagnosed this by running siege on two identical new droplets in different datacenters. Both were in default configuration running the sample MEAN app. The one in Amsterdam (where my original droplet is) had the same problem, the one in London was working perfectly fine. As I was preparing t

Categories : Node Js


Recently Add
How does Express SessionParser exactly store data on the client side?
In nodejs trying to get http-proxy to forward requests passing through query string parameters
Cassandra requesting data from a node which is down?
Node.js, socket.io and IIS 7
Result of socket.io request in IE 9 is Pending
Pattern for if(require.main) that works on Azure's iisnode
using flock inside crontab with node script throws an error
use GET method in node js request?
Is there any template engines in node.js like erb
Can't run express server on hostmonster
How do I use npm to install and run packages?
Use JavaScript libraries inside of Gruntfile
Strange behaviour of Mean.io on Azure VM‏
NodeJS getting stuck in callback
How to connect Mongoose in Bluemix
Error when using npm
Designing nodejs expressjs mongodb Webserver flow for desktop, mobile native apps and oAuth functionality
NVM - All The Packages I Installed with NPM Suddenly Stops Working
can't npm install bcrypt in my docker image
How do I customize nginx on AWS elastic beanstalk to loadbalance Meteor?
parsing data in Node.js
Add authentication provider to Azure Mobile Services Nodejs backend
node js callback ambiguity
can you use jade to only render the dynamic part of your html...and not mess with rest of your html
What does mean brackets in: require("./config")[somevar]
Overriding Relation Remote Method In Strongloop Loopback
Mongodb sort by either of two fields
Activate Node function on action
npm -v reports error when node.js has been installed
Automatic run gulp tasks via npm
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.