NodeJS脚本无法在Windows或Linux上运行

时间:2016-05-09 14:35:39

标签: linux node.js windows mongodb

在我们的一个内部项目中,我无法使用此错误运行server.js。我在Windows上尝试它,但是Ubuntu也提供了相同的功能。

为什么我要面对这个?

$ node src\server\server.js                                                                                 
Launching http server...                                                                                    
Connecting to database...                                                                                   
Listening on port 9090...                                                                                   
c:\projectAlpha\node_modules\mongodb\lib\server.js:242                                                  
        process.nextTick(function() { throw err; })                                                         
                                      ^                                                                     

TypeError: callback is not a function                                                                       
    at c:\projectAlpha\src\server\mongo_db.js:15:4                                                      
    at c:\projectAlpha\node_modules\mongodb\lib\mongo_client.js:330:20                                  
    at c:\projectAlpha\node_modules\mongodb\lib\db.js:231:14                                            
    at null.<anonymous> (c:\projectAlpha\node_modules\mongodb\lib\server.js:240:9)                      
    at g (events.js:273:16)                                                                                 
    at emitTwo (events.js:100:13)                                                                           
    at emit (events.js:185:7)                                                                               
    at null.<anonymous> (c:\projectAlpha\node_modules\mongodb-core\lib\topologies\server.js:218:12)     
    at g (events.js:273:16)                                                                                 
    at emitTwo (events.js:100:13)                                                                           

1 个答案:

答案 0 :(得分:0)

我没有在线获得任何直接帮助。 因此,想把它放在别人身上。

经过一些研究后,我怀疑它可能与MongoDB有关,因为我没有在我的系统上安装它,但这个特定的项目需要它。

所以,我下载了MongoDB(社区版)并安装了它。

然后,创建一个数据文件夹,并将其作为服务运行。

$ cd c:\
$ md \data\db
$ "C:\Program Files\MongoDB\Server\3.2\bin\mongod.exe" --dbpath c:\data
瞧,问题解决了。 $ node src\server\server.js跑得很好。