0

This code below is throwing a syntax error that I cannot seem to rectify.

The error specifically is as follows:

node staticapi.js
/Users/v/Desktop/CS-Extra/EIP/A5/staticapi.js:123
    res.status(200).send(“Api is running”)
                         

SyntaxError: Invalid or unexpected token
    at wrapSafe (internal/modules/cjs/loader.js:1152:16)
    at Module._compile (internal/modules/cjs/loader.js:1200:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1257:10)
    at Module.load (internal/modules/cjs/loader.js:1085:32)
    at Function.Module._load (internal/modules/cjs/loader.js:950:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
    at internal/main/run_main_module.js:17:47

Also i know how to create a route to accept the parameter for city in general but how do i create a route which filters my json result based on a specific city. Not just by cities in general but instead filter json by restaurants in Delhi per se.

 const app = express();
 const port = 8700;
 var location = [
     {
         "_id": 1,
         "name": "Pitampura, New Delhi",
         "city_name": "Delhi",
         "city": 1,
         "area": 11,
         "country_name": "India",
     },
     {
         "_id": 2,
         "name": "Ashok Vihar Phase 2",
         "city_name": "Delhi",
         "city": 1,
         "area": 12,
         "country_name": "India",
     },
     {
         "_id": 3,
         "name": "Laxmi Nagar",
         "city_name": "Delhi",
         "city": 1,
         "area": 13,
         "country_name": "India",
     },
     {
         "_id": 4,
         "name": "Lajpat Nagar 2",
         "city_name": "Delhi",
         "city": 1,
         "area": 14,
         "country_name": "India",
     },
     {
         "_id": 5,
         "name": "Borivali West",
         "city_name": "Mumbai",
         "city": 2,
         "area": 21,
         "country_name": "India",
     },
     {
         "_id": 6,
         "name": "Mira Road",
         "city_name": "Mumbai",
         "city": 2,
         "area": 22,
         "country_name": "India",
     },
     {
         "_id": 7,
         "name": "Sion",
         "city_name": "Mumbai",
         "city": 2,
         "area": 23,
         "country_name": "India",
     },
     {
         "_id": 8,
         "name": "Mohammad Ali Road",
         "city_name": "Mumbai",
         "city": 2,
         "area": 24,
         "country_name": "India",
     },
     {
         "_id": 9,
         "name": "Magarpatta",
         "city_name": "Pune",
         "city": 3,
         "area": 31,
         "country_name": "India",
     },
     {
         "_id": 10,
         "name": "Koregaon Park",
         "city_name": "Pune",
         "city": 3,
         "area": 32,
         "country_name": "India",
     },
     {
         "_id": 11,
         "name": "Rajajinagar",
         "city_name": "Bangalore",
         "city": 4,
         "area": 41,
         "country_name": "India",
     },
     {
         "_id": 12,
         "name": "Koramangala 6th Block",
         "city_name": "Bangalore",
         "city": 4,
         "area": 42,
         "country_name": "India",
     },
     {
         "_id": 13,
         "name": "Sector70, Chandigarh",
         "city_name": "Chandigarh",
         "city": 5,
         "area": 51,
         "country_name": "India",
     },
     {
         "_id": 14,
         "name": "Sector 28, Chandigarh",
         "city_name": "Chandigarh",
         "city": 5,
         "area": 52,
         "country_name": "India",
     }
 ];
 
 
 var cuisine = [abc];
 
 app.get(`/`,(req, res) (function() {
     res.status(200).send(“Api is running”)
 }));
 
 app.get(`/location`(req, res)(function () {
     res.status(200).send(location)
 
 }))
 
 app.get(`/cuisine`(req, res)(function () {
     res.status(200).send(cuisine)
 
 }))
 
 
 app.listen(port, (function (err) {
     if (err) throw err;
     console.log(`Server is running ${port}`)
 }))```




1 Answer 1

1

Probably because of the Unicode quotation marks (, ) on line 123. Try replacing them with regular quotation marks (").

Sign up to request clarification or add additional context in comments.

2 Comments

Works for sure but it is throwing a new error now. app.get(/,(req, res) (function() { ^ ReferenceError: req is not defined at Object.<anonymous> (/Users/varun/Desktop/CS-Extra/EIP/A5/staticapi.js:122:14)
@Varun It looks like you forgot to define an object. I don't have any experience with NodeJS Express, but the answers to this question will probably help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.