Search code examples
javascriptnode.jsclient-serverscreen-resolution

How to get screen resolution with node.js


I need get screen resolution with node.js, but the following code don't work.

var w = screen.width;
var h = screen.height;

This also don't work.

var w = window.screen.width;
var h = window.screen.height;

Someone know how to get screen resolution with node.js ? Thank you.


Solution

  • I solved the problem with phantomJS.

    Install phantomJS:

    sudo apt-get install phantomjs
    

    Create app.js file:

    var w = screen.width;
    var h = screen.height;
    
    console.log(w+"x"+h);
    
    phantom.exit();
    

    Execute:

    phantomjs app.js
    

    Return:

    1366x768