S C:\Users\user\OneDrive\Desktop\node\backend> node server.js
node:internal/modules/cjs/loader:988
throw err;
^
Error: Cannot find module 'C:\Users\user\OneDrive\Desktop\node\backend\server.js'
at Function.Module._load (node:internal/modules/cjs/loader:833:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:22:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
PS C:\Users\user\OneDrive\Desktop\node\backend> node server.js
node:internal/modules/cjs/loader:988
throw err;
^
Error: Cannot find module 'C:\Users\user\OneDrive\Desktop\node\backend\server.js'
PS C:\Users\user\OneDrive\Desktop\node\backend> node server.js
node:internal/modules/cjs/loader:988
throw err;
^
Error: Cannot find module 'C:\Users\user\OneDrive\Desktop\node\backend\server.js'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:985:15)
at Function.Module._load (node:internal/modules/cjs/loader:833:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:22:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
每当我运行node server.js时,我会得到上面的错误我已经分别运行npm安装,但都是徒劳的
const express = require("express")
var app = express()
const port = 3000
app.get('/', (_req, res) =>{
res.send('Hello World')
})
app.listen(port, ()=>{
console.log(`server is running on port number ${port}`)
})
我希望终端到控制台服务器在端口号3000上运行,我安装了express
,但被告知MODULE NOT FOUND
1条答案
按热度按时间zengzsys1#
你的代码看起来很好,应该可以运行,因为你之前使用了
npm init -y
和npm install express
。我想npm start
也会给你同样的错误吧?除此之外,您的代码似乎位于与OneDrive同步的文件夹中...您确定它已正确同步吗?您是否尝试过使用
more server.js
等字符显示server.js的内容?