Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a way to detect screen size in node.js?

Specifically, I would like to make a GET request to a nodejs server, then get the number of monitors and their resolutions for the server.

E.g.

app.get('/screens', (req, res) => {
    //return the screen info for the computer running this express server
})

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

With systeminformation package.

...
const si = require('systeminformation')

app.get('/screens', async(req, res, next) => {
  try {
    const {
      displays
    } = await si.graphics()

    if (!displays.length) {
      throw new Error('No displays')
    }

    res.json({
      displays: displays.length,
      x: displays[0].currentResX,
      y: displays[0].currentResY
    })
  } catch (err) {
    next(err)
  }
})
...

{ displays: 2, x: 1920, y: 1080 }

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading