EzDevInfo.com

connect

Connect is a middleware layer for Node.js Connect - High quality middleware for node.js

iOS Facebook connect not working when user has FB's app installed?

Has anyone else had this problem? I'm getting this error when trying to authorize a user via FB, I think I've isolated it only when a user has installed the Facebook app:

fb_our_appID://authorize#error=unknown%5Ferror

If you delete the FB app from the user's phone, our app will then try to authenticate via Safari, and everything works fine.

Thanks so much.


Source: (StackOverflow)

"connect EMFILE" error in Node.js

I have very recently received a lot of traffic to my site that runs Node.js. With the increasing traffic it has started to crash a lot, which has not happened before. I get the following error in my log:

{ [Error: connect EMFILE] code: 'EMFILE', errno: 'EMFILE', syscall: 'connect' }
Error: connect EMFILE
    at errnoException (net.js:670:11)
    at connect (net.js:548:19)
    at net.js:607:9
    at Array.0 (dns.js:88:18)
    at EventEmitter._tickCallback (node.js:192:40)

Anyone that have an idea why it crash? And ideas how to solve it?

I'm using Express.js and Socket.io. It runs on Ubuntu.


Source: (StackOverflow)

Advertisements

What is a good session store for a single-host Node.js production app?

I'm using Node's Express w/ Connect middleware. Connect's memory session store isn't fit for production:

Warning: connection.session() MemoryStore is not designed for a production environment, as it will leak memory, and obviously only work within a single process.

For larger deployments, mongo or redis makes sense.

But what is a good solution for a single-host app in production?


Source: (StackOverflow)

How do I output Connect/Express's logger output to Winston?

I'm making a Node.js app and I am using Winston for most of my logging purposes. I also aware of the Connect/Express logger function and know it has a stream option... Is it at all possible to output the stuff from Connect/Express's logger function to Winston? ...then I can have all the useful logging I need?

I find the logging that Connect/Express useful, but at the moment the two are sort of separate... I would must prefer to have it all running through Winston and it's transports.

How is that possible? Thanks, James


Source: (StackOverflow)

session secret? what is it

I don't know anything about cryptography. I'm wondering what the session secret is.

I see code like this:

  app.use(express.session({ store: mongoStore({url:app.set('db-uri')}), secret: 'topsecret' }));

What is the secret and should I change it?


Source: (StackOverflow)

How do i program a simple IRC bot in python?

I need help writing a basic IRC bot that just connects to a channel.. is anyone able to explain me this? I have managed to get it to connect to the IRC server but i am unable to join a channel and log on. The code i have thus far is:

import sockethost = 'irc.freenode.org'
port = 6667
join_sock = socket.socket()
join_sock.connect((host, port))
<code here> 

Any help would be greatly appreciated.


Source: (StackOverflow)

When to use next() and return next() in Node.js

Scenario: Consider the following is the part of code from a node web app.

app.get('/users/:id?', function(req, res, next){
    var id = req.params.id;
    if (id) {
        // do something
    } else {
        next();
    }
});

Issue: I am checking which one to go for just next() or return next(). For the above code sample both the codes works exactly the same way did not show any difference in execution part.

Question: Can some one put light of when to use next() and when to use return next() and some important difference?


Source: (StackOverflow)

Using static(), staticCache(), and compress() node.js connect middleware

I have an Express 3.0 app and I'm trying to use the static(), staticCache(), and compress() middleware to serve and compress my static files. This is my current app.configure() function:

 app.configure(function() {
  app.use(express.favicon(__dirname + '/public/favicon.ico', {maxAge: 86400000}));
  app.use(express.bodyParser());
  app.use(express.cookieParser('foo'));
  app.set('views', __dirname + '/views');
  app.engine('.html', mustache({cache: true}).render);
  app.use(express.session({ store: sessionStore, secret: 'foo'}));
  app.use(express.staticCache());
  app.use(express.static(__dirname + '/public', {maxAge: 86400000}));
  app.use(express.compress());
});

// routes are loaded here

With this configuration, YSlow reports that my .css and .js files are not compressed and I can't get a cache hit without clearing my browser and refreshing the page multiple times. I also tried putting in a debug statement in the staticCache middleware to report cache hits and running ab -n 10000 -c 500 shows 0 cache hits.

Obviously I'm doing something wrong (I'm guessing the order or options are messed up) but I can't figure out what it is. Anybody have a working example with these three pieces of middleware working correctly together?


Source: (StackOverflow)

itunes connect analytics availability?

I did google a lot and searched in developer forums and so on but i can not find any information about it. When will the analytics in itunes connect they showed at WWDC be available? I thought it comes when they update the whole itunes connect, they did an update but it was still missing. Then I thought it will be available when iOS 8 is released, but no. Then I thought you have to update your app using xcode 6 but no.

So is it only me or is the analytics feature in itunes connect still not be available. and if so, when will it be available? why apple does not give any information about it?

Thanks !


Source: (StackOverflow)

"Cannot GET /" with Connect on Node.js

I'm trying to start serving some static web pages using connect like this:

var connect = require("connect");
var nowjs = require("now");
var io = require("socket.io");


var app = connect.createServer(
  connect.static(__dirname + '/public')
);

app.listen(8180);

So I added a simple index.html at the /public directory on the same directory as the app.js file is, but when I try to view the page on my browser I get this response from node:

Cannot GET /

What I'm doing wrong and how I can correct it?


Source: (StackOverflow)

Check each node.js request for authentication credentials

I'm using node.js with Express and connect-auth to authenticate users.

This is the verification when requesting /index:

if(req.isAuthenticated()) {
  res.redirect('/dashboard');
} else {
  res.render('index', { layout: 'nonav' });
}

However, after logging out and going back to f.e. '/dashboard', I can see the dashboard.

How can I put the authentication check to every request to make sure there's a valid user at all times?

Update I don't have any problems with the authentication, everything works fine! I need a solution which checks every route/request if there's a valid user, without putting a function or if-statement in the route-implementation, as the whole App needs a valid user anyway. The Express-Authentication-Example uses "restrict" in the route-definition, which is close, but with many routes it can easily be forgotten.


Source: (StackOverflow)

What's the difference between BeginConnect and ConnectAsync?

What is the difference between BeginConnect and ConnectAsync? Subsequently, what is the difference between BeginDisconnect and DisconnectAsync?

The ConnectAsync documentation states:

"Begins an asynchronous request for a remote host connection."

The BeginConnect documentation also states:

"Begins an asynchronous request for a remote host connection."

Both the DisconnectAsync and BeginDisconnect also state the same thing:

"Begins an asynchronous request to disconnect from a remote endpoint."

What's the difference between those method pairs and which one should be used?


Source: (StackOverflow)

What properties does Node.js express's Error object expose?

I would like to know what are the functions the Error object of nodejs express exposes for use in Error Handling?

A console.log of an error call new Error('NotFound') is showing only [Error: NotFound], is this because .toString() method is overriden? How do find the properties and functions exposed by these objects?


Source: (StackOverflow)

Java URLConnection Timeout

I am trying to parse an XML file from an HTTP URL. I want to configure a timeout of 15 seconds if the XML fetch takes longer than that, I want to report a timeout. For some reason, the setConnectTimeout and setReadTimeout do not work. Here's the code:

          URL url = new URL("http://www.myurl.com/sample.xml");
          URLConnection urlConn = url.openConnection();
          urlConn.setConnectTimeout(15000);
          urlConn.setReadTimeout(15000);
          urlConn.setAllowUserInteraction(false);         
          urlConn.setDoOutput(true);

          InputStream inStream = urlConn.getInputStream();
          InputSource input = new InputSource(inStream);

And I am catching the SocketTimeoutException.

Thanks Chris


Source: (StackOverflow)

Node.js express correct use of bodyParser middleware

I am new to node.js and express and have been experimenting with them for a while. Now I am confused with the design of the express framework related to parsing the request body. From the official guide of express:

app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(logErrors);
app.use(clientErrorHandler);
app.use(errorHandler);

After setting up all the middleware, then we add the route that we want to handle:

app.post('/test', function(req, res){ 
  //do something with req.body      
});

The problem with this approach is that all request body will be parsed first before the route validity is checked. It seems very inefficient to parse the body of invalid requests. And even more, if we enable the upload processing:

app.use(express.bodyParser({uploadDir: '/temp_dir'}));

Any client can bombard the server by uploading any files (by sending request to ANY route/path!!), all which will be processed and kept in the '/temp_dir'. I can't believe that this default method is being widely promoted!

We can of course use the bodyParser function when defining the route:

app.post('/test1', bodyParser, routeHandler1);
app.post('/test2', bodyParser, routeHandler2);

or even perhaps parse the body in each function that handle the route. However, this is tedious to do.

Is there any better way to use express.bodyParser for all valid (defined) routes only, and to use the file upload handling capability only on selected routes, without having a lot of code repetitions?


Source: (StackOverflow)