2017-11-25 159 views
-2
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上创建数据库。无法弄清楚什么是错的。如何调试

回答

-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] 

连接错误

+0

要使用模板字符串,你需要使用反单引号 “'”。看起来你没有使用'$ {port}'。 此外,请避免反疑问。您可以根据需要创建新问题,或将其作为评论发布。在我们实际看到您的代码之前,我们无法调试此问题。 – weirdpanda

+0

我附上了代码。 –

+0

您的Mongo实例是否正在运行?如果是,配置在哪里?你如何连接到数据库? MongoError这一行应该告诉你,它与你的'server.js'文件无关;检查你的Mongo配置。 另外,将'localhost:$ {port}'改为'''在localhost上运行:$ {port} \'' – weirdpanda

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**