让我很想找出正确的文件路径。至少我认为这是文件路径错误。在Chrome中出现以下错误。
还在下面添加了我的index.js和app.js代码。我不明白为什么我的app.js mongodb运行正常?
---------app.js----------
const express = require("express");
const bodyParser = require("body-parser");
const ejs = require("ejs");
const app = express();
const mongoose = require("mongoose");
app.use(express.static("public"));
app.set("view engine", "ejs");
app.use(bodyParser.urlencoded({
extended: true
}));
mongoose.connect("mongodb://localhost:27017/userDB", {useNewUrlParser:true, useUnifiedTopology: true});
const Schema = mongoose.Schema;
const userSchema = new Schema({
username: String,
email: String,
password: String
});
const User = mongoose.model("User", userSchema);
app.get("/", function(req, res){
res.render("login");
});
app.get("/register", function(req, res){
res.render("register");
});
app.post("/register", function(req, res){
const newUser = new User({
username: req.body.username,
email: req.body.email,
password: req.body.password
});
newUser.save(function(err){
if(err){
console.log(err);
} else{
res.render("dashboard", {loggedInUser: req.body.username});
}
});
});
app.listen(3000, function(){
console.log("server is running on port 3000");
});
-index.js ----
alert(“ test”);
答案 0 :(得分:0)
您的两个src=""
标签指向错误的位置。
app.js
是一个目录,
/ChatApp
表示它指向/
目录。
Br, 杜尔贡