Nov 25, 2012

I wanted to try my local server in an iPad device and when I accessed its external port (192.168.0.24) in our intranet, it's not working. At first I changed the listen address from 127.0.0.1 to 192.168.0.24 and it worked, the problem was I cannot access http://localhost:3000 after. In addition, this approach of hardcoding the address is not an acceptable solution in the long run; there must be another way.

How to make your node js server listen to external ip

The fix is easy but not very intuitive. Just change the listen address from 127.0.0.1 to 0.0.0.0

I encountered a minor hiccup: I stored the address in a global variable and used it in a special function that accessed my own server. So my function was trying to access http://0.0.0.0:3000/... and it wouldn't work this way. So I just retained the 127.0.0.1 for my special functions.

I wonder why node js decided to implement it this way (or I'm not sure if it's Express js that's the culprit here). Why not just listen to all available IP Addresses when you specify 127.0.0.1? Maybe it's a security issue; I don't know.

[Update 18-Feb-2013] As "Reality Check" pointed out, NodeJS can listen to any IP address if you don't specify the host parameter. It's right here in NodeJs API:

server.listen(port, [hostname], [backlog], [callback])Begin accepting connections on the specified port and hostname. If the hostname is omitted, the server will accept connections directed to any IPv4 address (INADDR_ANY).

It seemed that my image was not preloaded fully so I tried preloading the image using javascript or css but to no avail. Found out that the problem is not in the preloading of image, it's the css definition. Apparently, Google Chrome thoughts it needs to reload the image even if you are using the same one.

The solution:

#MAIN_MENUa.foodMenu:hover{background-position:-525px0;}

Do not use background property to re-define the hover. Use background-position only to re-position the sprite. That's it!

Nov 10, 2012

If you've been using node.js, you're probably familiar with the following scenario:

book.js:

exports.title='The Alchemist'

reader.js:

varbook=require('./book');console.log(book.title);// prints "The Alchemist" to console

In the above, "exports" allows us to call the property "title" of book.js. However, this approach always requires us to define and call a method or property. The object returned by "require('./book')" is the exports object which is created by the node.js framework but what if we want our own custom object returned?

This when "module.exports" becomes useful:

book.js:

module.exports='The Alchemist';

reader.js:

varbook=require('./book');console.log(book);// prints "The Alchemist" to console

In the above, notice that we don't need to call any method of book to be able to use it. In some cases, module.exports may be more convenient. In Express js, I use this approach to modularize my routes.

Nov 6, 2012

There are cases that did rotate method (didRotateFromInterfaceOrientation:) of a view controller is not triggered. A workaround is to manually call it from you main view controller, but if you don't have time, an easier fix is to use notifications:

The author is Manuel Vergel aka Manny. He's an experienced software developer in the Philippines. He's passionate about programming and sharing web development knowledge to the Filipino youth. He's into Java, Oracle, iOS (iPhone and iPad) development. Along with his blog in mvergel.com, he also authors Pesobility.com and is the co-creator of JuanSolution.com. (more)