简体   繁体   English

我在我的节点 js 代码中收到错误意外的输入结束

[英]i am getting error unexpected end of input in my node js code

 const express = require("express");
const bodyParser = require("body-parser");
const ejs = require("ejs");
  const mongoose = require('mongoose');

const app = express();

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

app.use(bodyParser.urlencoded({
 extended: true
}));
app.use(express.static("public"));


mongoose.set('useUnifiedTopology', true);

mongoose.connect("mongodb://localhost:27017/restDB",{useNewUrlParser:true});

const articleSchema={
 title:String,
content:String
 }
 const Article = mongoose.model("Article",articleSchema);

app.get("/articles",function(req,res){
  Article.find(function(err,foundArticles){
  if(!err){
   res.send(foundArticles)
  }else{
   res.send(err)
   }

  });
 });

   app.post("/articles",function(req,res){
     const newArticle = Article({
    title:  req.body.title,
     content:  req.body.content
    });
   newArticle.save(function(err){
    if(!err){
    res.send("succes")
     }else{
    res.send(err)
    }
       })
   app.delete("/articles",function(req,res){
       Article.deleteMany(function(err){
      if(!err){
       res.send("success")
    }else{
     res.send(err)
    }
   });
    });



    app.listen(3000, function() {
      console.log("Server started on port 3000");
     });

i am making request through postman the same code was running fine but it started giving this error before this error code was doing fine and i dont understand whats happening我正在通过邮递员发出请求,同样的代码运行良好,但在此错误代码运行良好之前它开始出现此错误,我不明白发生了什么

    SyntaxError: Unexpected end of input
      at wrapSafe (internal/modules/cjs/loader.js:1071:16)
     at Module._compile (internal/modules/cjs/loader.js:1121:27)

        at internal/main/run_main_module.js:18:47

please help me with that it doest include html file i am making requst with postman and using mongodb as a database请帮助我,它不包含 html 文件,我正在使用邮递员请求并使用 mongodb 作为数据库

Please recheck your closing bracket请重新检查您的右括号

your api with endpoint articles isn't closed.您带有端点文章的 api 未关闭。

 app.post("/articles", function (req, res) {
    const newArticle = Article({
        title: req.body.title,
        content: req.body.content
    });
    newArticle.save(function (err) {
        if (!err) {
            res.send("succes")
        } else {
            res.send(err)
        }
    });
});

A SyntaxError: Unexpected end of input error typically means either you are missing a closing parenthesis, brace, bracket, or similar character somewhere in your code or you are trying to JSON.parse() a string that is missing such characters. SyntaxError: Unexpected end of input error通常意味着您在代码中的某处缺少右括号、大括号、方括号或类似字符,或者您正在尝试JSON.parse()缺少此类字符的字符串。

Run your code/JSON string through a javascript linter (eg jshint) to find syntax errors.通过 javascript linter(例如 jshint)运行您的代码/JSON 字符串以查找语法错误。

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

相关问题 我的 html 代码中的输入错误意外结束 - Unexpected end of input error in my html code 为什么收到“ Uncaught SyntaxError:JSON输入意外结束”? - Why am I getting 'Uncaught SyntaxError: Unexpected end of JSON input'? “输入错误意外结束” - node.js discord 机器人 - “Unexpected End of Input Error” - node.js discord bot Node.js —未定义:0语法错误:输入意外结束 - Node.js — Undefined:0 Syntax Error: Unexpected end of input Node.js [系统:输入意外结束] 错误(再次) - Node.js [system: unexpected end of input] error (again) 为什么在脚本的第一行出现JS错误语法错误:无效或意外的令牌? - Why am I getting the JS error in line one of my script Syntax error: invalid or unexpected token? 我在我的 node.js 代码中收到此错误“无法读取未定义的属性 'split'”。 如何解决这个问题? - I am getting this error “Cannot read property 'split' of undefined” in my node.js code. How to resolve this? 我的 discord 机器人出现“SyntaxError: Unexpected end of input” - I'm getting a “SyntaxError: Unexpected end of input” on my discord bot 我收到此错误:SyntaxError:输入的意外结束; Cookie创建代码有什么问题? - I got this error: SyntaxError: Unexpected end of input; What is wrong with my cookie creating code? JSON 输入 node.js 意外结束 - Unexpected end of JSON input node.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM