0

Good evening to everyone,i am trying to get the graphics info from systeminformation node_module but nothing is displayed in my ejs page. I tried to display the gpu name in my console so i did, but my function is not working on the /home page. My public folder has a main web page with a link to the /home page.Everything seems to work fine except that gpu name problem.

Can anyone help me?

My index.js file

const express = require("express");
const app = express();
const path = require("path");
const si = require("systeminformation");

app.use(express.static("public"));

app.set('view engine', 'ejs');
app.set('views',path.join(__dirname,'/views'))

app.get('/home',(req,res) => {

    const gpu = si.graphics().then(res => {
        return res.controllers[0].model;
    })    
 
    const printGpu = () => {
        gpu.then((a)=>console.log(a))
    }

    const gpuRes = printGpu();
    res.render("home.ejs",{gpuRes})
 })

 app.listen(3000,() => {
      console.log("listening on port 3000")
 })

In my home.ejs file

i got the

 <body>
    ..
     <h2><%= gpuRes %></h2>
    ..
 </body>
rand0m
  • 842
  • 10
  • 24
Dante
  • 1
  • 2
  • `gpuRes` is the return value of `printGpu` which doesn't have a `return` statement so `gpuRes` is undefined. What did you expect to happen? – Quentin Mar 29 '21 at 16:40
  • I am new in programming so i didn't know what to expect to tell you the truth. I guess to print the result. Thank you for responding – Dante Mar 29 '21 at 16:46
  • It does print the result, but the result is nothing at all. – Quentin Mar 29 '21 at 16:47
  • when you call `gpuRes`, it calls `printGpu` and `printGpu` expects `gpu` to be ready to consume, and that's where I believe lies the problem, You need to modify your code so that you need to call the `gpu` inside your `printGpu` and make sure that the `collection` contain anything before you access the indexed item and its properties – rand0m Mar 29 '21 at 16:51
  • Thank you for your answer!! – Dante Mar 29 '21 at 16:57

0 Answers0