2 years ago

#65614

test-img

A. Hasemeyer

Consume OData on Express.js Promise Issue

I am setting up a React backend server that I need to get data from an OData server.

I have installed the o.js package and I am following their startup guide https://www.npmjs.com/package/odata.

However, I am getting an error using the code they have provided.

TypeError: o(...).get(...).then is not a function

Here is my index.js on the Express server

const express = require("express");
const o = require('odata').o;

const PORT = process.env.PORT || 3001;

const app = express();

app.get("/api", (req, res) => {
    res.json({ message: "Hello from server!" });
});

app.get("/odata", (req, res) => {

    o('https://localhost:44335/odata')
        .get('OpenTask')
        .then((data) => console.log(data));

    res.json({ message: "odata" });
})

app.listen(PORT, () => {
  console.log(`Server listening on ${PORT}`);
});

The line o('https://localhost:44335/odata') is what is throwing the error and what is on the o.js site.

The OData service is working, as I am able to connect to it on Postman.

Why is the promise error happening?

javascript

node.js

express

odata

0 Answers

Your Answer

Accepted video resources