我执行node test1.js 报以下错误
F:\代码练习\代码练习\Nodejs\test4>node test1.js
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module 'F:\代码练习\代码练习\Nodejs\test4\test1.js'
[90m at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)[39m
[90m at Function.Module._load (node:internal/modules/cjs/loader:778:27)[39m
[90m at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)[39m
[90m at node:internal/main/run_main_module:17:47[39m {
code: [32m'MODULE_NOT_FOUND'[39m,
requireStack: []
}
F:\代码练习\代码练习\Nodejs\test4>
//数据模型(规范数据格式) const mongoose = require('./db') //定义schema (数据规范) const UserSchema = mongoose.Schema({ username:{ type:String, required:true, unique:true }, password:String, age:Number, city:String, //性别 gender:{ type:Number, default:0 } },{ timestamps:true // } ) //定义model const User = mongoose.model('user',UserSchema) module.exports = { User } const mongoose = require('mongoose') const url = 'mongodb://localhost:27017' const dbName = 'comment2' mongoose.connect(`${url}/${dbName}`,{ useNewUrlParser:true, useUnifiedTopology:true }) const conn = mongoose.connection conn.on('error',err =>{ console.error('mongoose 连接出错',err); }) // module.exports = mongoose //commonjs const {User} = require('./model') console.log('ok');
11
收起
正在回答 回答被采纳积分+1
1回答
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星