Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Victor Alfonso's avatar

TypeError - u.get is not a function

I'm getting this response from a small api I'm trying to make in vanilla JS with node.js and express.js.

Error:

Dec 18, 11:29:42 PM: 2022-12-19T05:29:42.736Z	undefined	ERROR	Uncaught Exception 	{"errorType":"TypeError","errorMessage":"c.get is not a function","stack":["TypeError: c.get is not a function","    at Object.<anonymous> (/var/task/api.js:162:12982)","    at i (/var/task/api.js:1:158)","    at /var/task/api.js:1:957","    at Object.<anonymous> (/var/task/api.js:1:967)","    at Module._compile (node:internal/modules/cjs/loader:1105:14)","    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)","    at Module.load (node:internal/modules/cjs/loader:981:32)","    at Function.Module._load (node:internal/modules/cjs/loader:822:12)","    at Module.require (node:internal/modules/cjs/loader:1005:19)","    at require (node:internal/modules/cjs/helpers:102:18)"]}

This will return random users from other API call:

const express = require("express");
const { faker } = require('@faker-js/faker');
const bodyParser = require('body-parser');
const serverless = require("serverless-http");
const app = express();
const router = express.Router()
const cors = require("cors");;
const axios = require('axios');
router.get("/", (req, res) => {
    res.json({
        hello: "hi!"
    });
});
app.use(cors())
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));

// parse application/json
app.use(bodyParser.json());

let users = [];
let ramusers;

axios.get('https://randomuser.me/api?results=10')
    .then(function (response) {
        ramusers = response.data.results;
    })
    .catch(function (error) {
        console.log(error);
    });

function getUsers() {
    return ramusers;
}

router.get('/random-users', (req, res) => {
    res.send(getUsers());
});

In local by starting the server using the :

// start the server
app.listen(3000, () => {
    console.log('Server listening on port 3000');
});

#And then in the console run node .\src\api.js

So in local starting the local server I able to get all the data: https://imgur.com/a/c0pUcRu

Any idea what is happening here?

0 likes
0 replies

Please or to participate in this conversation.