简体   繁体   English

如何纠正 NodeJS express 服务器代码的语法错误?

[英]How to rectify syntax error that of a NodeJS express server code?

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.我也知道如何创建一条路线来接受一般城市的参数,但是我如何创建一条路线来根据特定城市过滤我的 json 结果。 Not just by cities in general but instead filter json by restaurants in Delhi per se.不仅仅是按一般城市,而是按德里的餐馆本身过滤 json。

 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}`)
 }))```




可能是因为第 123 行的 Unicode 引号( )。尝试将它们替换为常规引号( " )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM