Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

113
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda