[英]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.