Passing a JSON from another js file with Express and EJS

I am working on a project to manage printers with CUPS command-line, I have multiple "api’s" that make different thinks, for now i just want so see my parsed JSON result in a view, but I’m clueless on how to pass that value trough Express and then render it in a EJS view:

my api:

const spawnSync = require("child_process").spawnSync;
const parseStdout = require('../utils/utils.js');

function lpstat(){
let printerList = spawnSync("lpstat -p", {
    timeout: 10000,
    encoding: "utf-8",
  let parsedList = parseStdout(printerList);
  let onlyPrinterList = parsedList.filter(function (line) {
    return line.match(line.match(/^printer/) || line.match(/^impressora/));
  let onlyPrinterNames = (printer) {
    return printer.match(/(?: \S+)/)[0].trim();
  process.on('exit', (code) => {
  //this is what i want to pass to the view
   return JSON.stringify(onlyPrinterNames);

my app.js

const express = require('express');
const app = express();

app.set('view engine', 'ejs');

app.get('/lpstat',(req,res) => {
//what should i use here?

my lpstat.ejs

<html lang="en">
    <meta charset='utf-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <meta name='viewport' content='width=device-width, initial-scale=1'>
    <p>lpstat result:</p>
   <%= what should i use here?%>

99 thoughts on “Passing a JSON from another js file with Express and EJS”