Tag Archives: node.js

How to configure Java heap size for node.js JDBC module?

In my node.js application, I'm using JDBC to connect to a Oracle database. I need to increase my java heap space to prevent following error:

java.lang.OutOfMemoryError: Java heap space

I know that there is a terminal option for setting maximum Java heap size (-Xmx<size>) but the problem is, I don't explicitly run java, it happens inside my JDBC module (which depends on java module), so I can't use that terminal option.

So how java heap size can be configured in my case?

How to configure Java heap size for my node.js application?

In my node.js application, I'm using JDBC to connect to a Oracle database. I need to increase my java heap space to prevent following error:

java.lang.OutOfMemoryError: Java heap space

I know that there is a terminal option for setting maximum Java heap size (-Xmx<size>) but the problem is, I don't explicitly run java, it happens inside my JDBC module (which depends on java module), so I can't use that terminal option.

So how java heap size can be configured in my case?

When using node.js cluster, how to access a worker’s environment when it dies?

I'm using node.js cluster module to create worker processes. And I set a custom variable in each worker's environment as I fork it.

I need to read that custom variable when a worker dies, but when a worker dies, I can't access its environment object anymore.

This is what I tried so far:

var cluster = require('cluster'),
    os = require('os');

if (cluster.isMaster) {

    cluster.on('exit', function (worker, code, signal) {

        console.log('worker ' + worker.process.pid + ' died');

        var x = {
            workerId: worker.process.env.workerId // This is undefined.
        };
        cluster.fork(x);
    });

    for (var i = 0; i < os.cpus().length; i++) {
        var x = {
            workerId: i
        };
        cluster.fork(x);
    }

}
else {
    console.log("workerId: ", process.env.workerId);

    // simulate an exeption:
    throw "fakeError";

}

I know that's not gonna work, my question is: how to access to latest state of a worker's envoronment right before its death?

When using node.js cluster, how to access a worker’s environment when it dies?

I'm using node.js cluster module to create worker processes. And I set a custom variable in each worker's environment as I fork it.

I need to read that custom variable when a worker dies, but when a worker dies, I can't access its environment object anymore.

This is what I tried so far:

var cluster = require('cluster'),
    os = require('os');

if (cluster.isMaster) {

    cluster.on('exit', function (worker, code, signal) {

        console.log('worker ' + worker.process.pid + ' died');

        var x = {
            workerId: worker.process.env.workerId // This is undefined.
        };
        cluster.fork(x);
    });

    for (var i = 0; i < os.cpus().length; i++) {
        var x = {
            workerId: i
        };
        cluster.fork(x);
    }

}
else {
    console.log("workerId: ", process.env.workerId);

    // simulate an exeption:
    throw "fakeError";

}

I know that's not gonna work, my question is: how to access to latest state of a worker's envoronment right before its death?

How to create a user in MongoDB v3.0.5

I need to create a user for my database in mongodb, but it seems that I can't get it to work.

I have installed mongoDb v3.0.5 on my windows 7 machine. according to this article, I connected to my mongo instance using:

mongo -u siteUserAdmin -p password

and then I created first user via:

use admin
db.createUser(
  {
    user: "siteUserAdmin",
    pwd: "password",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
  }
)

then I created a user for my nodejs application on exampleDb:

use admin
db.createUser(
  {
    user: "myUser",
    pwd: "123456",
    roles: [ { role: "readWrite", db: "exampleDb" } ]
  }
)

and finally in my nodejs application, when I try to connect to my mongo instance using this connection string:

var connString = "mongodb://myUser:123456@127.0.0.1:27017/exampleDb";

an Authentication failed error happens:

{ name: 'MongoError',
  message: 'Authentication failed.',
  ok: 0,
  code: 18,
  errmsg: 'Authentication failed.'
}

How to create a user in MongoDB v3.0.5

I need to create a user for my database in mongodb, but it seems that I can't get it to work.

I have installed mongoDb v3.0.5 on my windows 7 machine. according to this article, I connected to my mongo instance using:

mongo -u siteUserAdmin -p password

and then I created first user via:

use admin
db.createUser(
  {
    user: "siteUserAdmin",
    pwd: "password",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
  }
)

then I created a user for my nodejs application on exampleDb:

use admin
db.createUser(
  {
    user: "myUser",
    pwd: "123456",
    roles: [ { role: "readWrite", db: "exampleDb" } ]
  }
)

and finally in my nodejs application, when I try to connect to my mongo instance using this connection string:

var connString = "mongodb://myUser:123456@127.0.0.1:27017/exampleDb";

an Authentication failed error happens:

{ name: 'MongoError',
  message: 'Authentication failed.',
  ok: 0,
  code: 18,
  errmsg: 'Authentication failed.'
}

How to extend q.promise in node.js?

I need to extent q.promise with my own functions, I tried:

defer = q.defer();
defer.promise.prototype.funcName = function () {
    // my function
}

witch returns following error:

TypeError: Cannot set property 'funcName' of undefined

How should I properly extend q.promise?


This is my actual problem: I need an alias for .then() witch gets name of an operation as argument (instead of a function), and executes that operation according to a internal library of functions.

How to transfer contexts among separate node.js environments? [closed]

Lets suppose I have my app running on machine A, at some point I need to shut down that machine, and transfer my app to machine B to continue its process. so I need to be able to save and restore context of my app.

How can implement that?

To be more specific, my question is: How can I save/restore application context in node.js?

How to transfer contexts among seperate node.js environments?

Lets suppose I have my app running on machine A, at some point I need to shut down that machine, and transfer my app to machine B to continue its process. so I need to be able to save and restore context of my app.

How can implement that?

To be more specific, my question is: How can I save/restore application context in node.js?

How to transfer contexts among separate node.js environments? [closed]

Lets suppose I have my app running on machine A, at some point I need to shut down that machine, and transfer my app to machine B to continue its process. so I need to be able to save and restore context of my app.

How can implement that?

To be more specific, my question is: How can I save/restore application context in node.js?

Preserve `this` with recursive setImmediate()

In my node.js app, I need to use setImmediate() to recessively call a function and keep its context intact for next execution.

Consider following example:

var i=3;

function myFunc(){
    console.log(i, this);
    --i && setImmediate(arguments.callee);
}

myFunc();

Output:

3 // a regular `this` object
2 { _idleNext: null, _idlePrev: null, _onImmediate: [Function: myFunc] }
1 { _idleNext: null, _idlePrev: null, _onImmediate: [Function: myFunc] }

As you can see, after first execution this is overwritten. How should I work around this?

Preserve `this` with recursive setImmediate()

Salam (means Hello:))

In my node.js app, I need to use setImmediate() to recessively call a function and keep its context intact for next execution.

Consider following example:

var i=3;

function myFunc(){
    console.log(i, this);
    --i && setImmediate(arguments.callee);
}

myFunc();

Output:

3 // a regular `this` object
2 { _idleNext: null, _idlePrev: null, _onImmediate: [Function: myFunc] }
1 { _idleNext: null, _idlePrev: null, _onImmediate: [Function: myFunc] }

As you can see, after first execution this is overwritten. How should I work around this?

PHP vs. Node.js: An epic battle for developer mind share | InfoWorld

It’s a classic Hollywood plot: the battle between two old friends who went separate ways. Often the friction begins when one pal sparks an interest in what had always been the other pal’s unspoken domain. In the programming language version of this movie, it’s the introduction of Node.js that turns the buddy flick into a grudge match: PHP and JavaScript, two partners who once ruled the Internet together but now duke it out for the mind share of developers. In the old days, the partnership was simple. JavaScript handled little details on the browser, while PHP managed all the server-side tasks that existed between port 80 and MySQL. It was a happy union that continues to support many of the crucial parts of the Internet. Between WordPress, Drupal, and Facebook, people can hardly go a minute on the Web without running into PHP.

10 Tips to Make Your Node.js Web App Faster

Node.js is already blazing fast thanks to its event driven and asynchronous nature. But, in the modern web just being fast is not enough. If you are planning to develop your next web app using Node.js you must take every possible step to make sure your app is faster than usual. This article presents 10 tips that are known to speed up your Node based web app tremendously. So, let’s see each of them one by one.