module.js:471
throw err;
^
Error: Cannot find module '..models/article'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\Sankalp Singhai\blogapp\server\routes\api.js
:4:17)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\Sankalp Singhai\blogapp\server.js:7:13)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
在哪里查找模块文件夹?是数据库连接中的错误。在mlab上创建了数据库。
答案 0 :(得分:0)
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const http = require('http');
const app = express();
const api = require('./server/routes/api');
//parsers
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended : false}));
app.use(express.static(path.join(__dirname,'dist')));
app.use('/api' , api)
app.get('*', (req,res)=>{
res.sendFile(path.join(__dirname, 'dist/index.html'));
});
//set port
const port = process.env.PORT || '3000';
app.set('port' , port);
const server = http.createServer(app);
server.listen(port, () => console.log('Running on localhost: ${port}'));
**server.js**
答案 1 :(得分:-1)
C:\Users\Sankalp Singhai\blogapp>node server.js
(node:4068) DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0, us
e `openUri()` instead, or set the `useMongoClient` option if using `connect()` o
r `createConnection()`. See http://mongoosejs.com/docs/connections.html#use-mong
o-client
Running on localhost: ${port}
Error connecting
(node:4068) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejec
tion id: 1): MongoError: failed to connect to server [6:27017] on first connect
[MongoError: getaddrinfo ENOTFOUND 6 6:27017]
连接错误