Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

111
Vistas
Exporting a module to a server request that reads JSON content

Basically, I have an array that needs to get passed through a function (using JSON). This becomes a module that I can export to a server request. When the request gets "transaction.html", the module should be called upon and the JSON object should print out. I have tried to make this work with no success and wondering what is that I am doing wrong here (new to JS!)

//this is becomes the transactionmanager module
    var arrayValues = [
    {
        date: "April 3, 2021",
        description: "House",
        category: "Mortgage",
        amount: 1500
    },
    {
        date: "March 7, 2022",
        description: "Duke Energy",
        category: "Bills and utilities",
        amount: 200
    },
    {
        date: "January 24, 2022",
        description: "Publix",
        category: "Shopping",
        amount: 120
    },
    {
        date: "May 15, 2022",
        description: "AMC",
        category: "Entertainment",
        amount: 20
    }
    ];

function getTransactions() {
    var values = JSON.parse(arrayValues);
}

exports.getTransactions = getTransactions;

And this is the server request below:

var http = require("http");
var url = require("url");
var transactions = require("transactionmanager");

var server = http.createServer(function (req, res) {
    if (req.url == "/index.html") {
        res.writeHead(200, {"Content-type": "text/html"});
        res.write("<html><body><p>Welcome!</p></body></html>");
        res.end();
    } else if (req.method == "GET" && req.url == "/transactions.html") {
        res.writeHead(200, {"Content-type": "text/html"});
        res.write("<html><body><p>Transaction History</p></body></html>");
        var content = transactions.getTransactions();
        res.end(content);
    } else {
        res.writeHead(404, {"Content-type": "text/html"});
        res.end("<html><body><p>Sorry, the page you are looking for is not here</p></body></html>");
        return;
    }
});

server.listen(3000);
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

In the the transactionmanager module, you have a getTransactions function that doesn't return the values

function getTransactions() {
    var values = JSON.parse(arrayValues);
}

then you tried to get back the values

var content = transactions.getTransactions();

You have to raturn the values

function getTransactions() {
    var values = JSON.parse(arrayValues);
    return values;
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda