DEV Community

Sanket N Jain
Sanket N Jain

Posted on

I am getting an error while using express and axios

I am using API to display movie search using express and axios when the user searches for a particular movie and I got some error after running the server.

Here is the express code:

var express = require("express");
const axios = require("axios");
var app = express();

app.set("view engine", "ejs");

app.get("/results", async function(req, res){
try{
const response = await axios.get('http://www.omdbapi.com/?s=hangover&apikey=thewdb');
res.render("results", {data:response.data});
}
catch(err){
console.log(err);
}
});

app.listen(3000, function(){
console.log("sever listening to port 3000");
});

And here is results.ejs file:

Alt Text

Here is the error:

Alt Text

Top comments (4)

Collapse
 
thughes24 profile image
Tom Hughes

It looks like the error is from the second bracket after the function definition inside the for loop.

So;
forEach(function(movie)) { ... }

Would become;
forEach(function(movie) { ... })

Collapse
 
sanketnjain5 profile image
Sanket N Jain

Thank you it was such a silly mistake and I couldn't find it!!

Collapse
 
sfiquet profile image
Sylvie Fiquet

It looks like the closing bracket ) is in the wrong place, it should be after the closing curly bracket } I think, to close forEach.

Collapse
 
sanketnjain5 profile image
Sanket N Jain

Thank you it was such a silly mistake and I couldn't find it!!