我在用mongoose作为后端之类的node js中构建代码结构时遇到问题,我需要这样的代码结构,第一个是第二个,第二个是这样。设置代码结构时会感到困惑。
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.json({ extended: false }))
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
mongoose.connect('URL Something', {
useNewUrlParser: true
});
const signUpSchema = new mongoose.Schema({
first_name: String,
last_name: String,
password: String,
email: String,
phone: String,
})
const User_details = mongoose.model('User_details', signUpSchema)```