Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

106
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!