我正在开发一个需要使用node server.js文件的项目。该项目的文档声明在终端中键入'node server.js'以启动服务器,但是当我这样做时,我收到错误,找不到模块'express'。
Error: Cannot find module 'express'
at Function.Module._resolveFilename (module.js:455:15)
at Function.Module._load (module.js:403:25)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/.../Desktop/react/react-app-project/server.js:6:15)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
这是server.js中的代码
var express = require('express');
var app = express();
/*
this says: serve all the files in the src directory if they match the URL
For example, if the client requests http://server/css/app.css then the file in src/css/app.css will be served
But if the client requests http://server/step-2 then since there is no file by that name the middleware will call next()
*/
app.use(express.static(__dirname + '/src'));
/* insert any app.get or app.post you need here. only if you do the advanced part */
/*
This says: for any path NOT served by the middleware above, send the file called index.html instead.
For example, if the client requests http://server/step-2 the server will send the file index.html. Then on the browser, React Router will load the appropriate component
*/
app.get('/*', function(request, response) {
response.sendFile(__dirname + '/src/index.html');
});
app.listen(process.env.PORT || 8080, function() {
console.log('server started');
});
答案 0 :(得分:0)
无法找到模块'express'
原因是你还没有安装快递。
解决方案:repB