Please see my question in image. I opened Mongoose, type "nodemon app.js" but cannot run my app.js successfully (it said "SyntaxError: Invalid or unexpected token"). I am not sure whether it's because I didn't finish the code, but I'm supposed to see "Success" in my hyper but not the SyntaxError. Thank you so much! A newbie here~
const express = require("express");
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
const app = express();
app.set('view engine', 'ejs');
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static("public"));
mongoose.connect("mongodb://localhost:27017/todolistDB", {useNewUrlParser: true});
const itemsSchema = new mongoose.Schema({
name: String
});
const Item = mongoose.model("Item", itemsSchema);
const item1 = new Item ({
name: "Drink milk"
});
const item2 = new Item ({
name: "Eat egg"
});
const defaultItems = [item1, item2];
Item.insertMany(defaultItems, function(err) {
if (err){
console.log(err);
} else {
console.log("Success");
}
});
app.get("/", function(req, res) {
res.render("list", {listTitle: "Today", newListItems: defaultItems});
});
app.post("/", function(req, res){
const item = req.body.newItem;
if (req.body.list === "Work") {
workItems.push(item);
res.redirect("/work");
} else {
items.push(item);
res.redirect("/");
}
});
app.listen(3000, function() {
console.log("Server started on port 3000");
});