我已经支付了会员费,下载了this project个.在npm installnode app.js之后,返回以下错误:

有人知道怎么了吗?

/Users/Thomas/Desktop/mean-stack-tutorial-01$ node app.js 

/Users/Thomas/Desktop/mean-stack-tutorial-01/node_modules/mongodb/lib/server.js:265
        process.nextTick(function() { throw err; })
                                      ^
MongoError: failed to connect to server [localhost:27017] on first connect
    at Pool.<anonymous> (/Users/Thomas/Desktop/mean-stack-tutorial-01/node_modules/mongodb-core/lib/topologies/server.js:325:35)
    at emitOne (events.js:96:13)
    at Pool.emit (events.js:188:7)
    at Connection.<anonymous> (/Users/Thomas/Desktop/mean-stack-tutorial-01/node_modules/mongodb-core/lib/connection/pool.js:270:12)
    at Connection.g (events.js:292:16)
    at emitTwo (events.js:106:13)
    at Connection.emit (events.js:191:7)
    at Socket.<anonymous> (/Users/Thomas/Desktop/mean-stack-tutorial-01/node_modules/mongodb-core/lib/connection/connection.js:173:49)
    at Socket.g (events.js:292:16)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at emitErrorNT (net.js:1281:8)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)

Edit 1:在 comments 之后,我刚刚通过brew安装了mongo,然后执行了brew services start mongodbmongo:

/Users/Thomas$ mongo
MongoDB shell version v3.4.1
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.1
Server has startup warnings: 
2017-01-12T19:53:01.868+0800 I CONTROL  [initandlisten] 
2017-01-12T19:53:01.869+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-01-12T19:53:01.869+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-01-12T19:53:01.869+0800 I CONTROL  [initandlisten] 

然后我做到了

/Users/Thomas$ mongod -httpinterface --dbpath /Users/Thomas/Desktop/MongoDB/db
2017-01-12T20:14:05.620+0800 I CONTROL  [initandlisten] MongoDB starting : pid=47356 port=27017 dbpath=/Users/Thomas/Desktop/MongoDB/db 64-bit host=Pro.local
2017-01-12T20:14:05.621+0800 I CONTROL  [initandlisten] db version v3.4.1
2017-01-12T20:14:05.621+0800 I CONTROL  [initandlisten] git version: 5e103c4f5583e2566a45d740225dc250baacfbd7
2017-01-12T20:14:05.621+0800 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2j  26 Sep 2016
2017-01-12T20:14:05.621+0800 I CONTROL  [initandlisten] allocator: system
2017-01-12T20:14:05.621+0800 I CONTROL  [initandlisten] modules: none
2017-01-12T20:14:05.621+0800 I CONTROL  [initandlisten] build environment:
2017-01-12T20:14:05.621+0800 I CONTROL  [initandlisten]     distarch: x86_64
2017-01-12T20:14:05.621+0800 I CONTROL  [initandlisten]     target_arch: x86_64
2017-01-12T20:14:05.621+0800 I CONTROL  [initandlisten] options: { storage: { dbPath: "/Users/Thomas/Desktop/MongoDB/db" } }
2017-01-12T20:14:05.657+0800 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=3584M,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2017-01-12T20:14:14.108+0800 I CONTROL  [initandlisten] 
2017-01-12T20:14:14.108+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-01-12T20:14:14.108+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-01-12T20:14:14.108+0800 I CONTROL  [initandlisten] 
2017-01-12T20:14:14.108+0800 I CONTROL  [initandlisten] 
2017-01-12T20:14:14.109+0800 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
2017-01-12T20:14:15.390+0800 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/Users/Thomas/Desktop/MongoDB/db/diagnostic.data'
2017-01-12T20:14:16.303+0800 I INDEX    [initandlisten] build index on: admin.system.version properties: { v: 2, key: { version: 1 }, name: "incompatible_with_version_32", ns: "admin.system.version" }
2017-01-12T20:14:16.304+0800 I INDEX    [initandlisten]      building index using bulk method; build may temporarily use up to 500 megabytes of RAM
2017-01-12T20:14:16.406+0800 I INDEX    [initandlisten] build index done.  scanned 0 total records. 0 secs
2017-01-12T20:14:16.407+0800 I COMMAND  [initandlisten] setting featureCompatibilityVersion to 3.4
2017-01-12T20:14:16.407+0800 I NETWORK  [thread1] waiting for connections on port 27017

然后在另一个终端上,我做了node app.js个,它挂起(不打印任何内容).然后我在浏览器中执行http://localhost:28017,它似乎可以工作:

enter image description here

然而,我怎样才能看到这个网站呢?

Edit 2:

正常的过程是

  1. 安装mongo

  2. 航站楼里有brew services start mongodb

  3. mongo &(假设我们使用默认文件夹/data/db/)

  4. 一百

  5. 例如,端口号请参见bin/www,然后在浏览器中使用localhost:the_port_number

推荐答案

Update 2020 Feb 24:

继续关注它是明智的.以下是最新图书馆指南的链接:

https://docs.mongodb.com/manual/administration/install-community/


你还没有启动monogo数据库.首先安装mongo install mongo as per your OS https://docs.mongodb.com/v3.0/tutorial/

然后按照本网站上的说明进行操作:

  1. 光盘
  2. mongod--dbpath"启动数据库的任何目录路径"

然后启动 node 服务器.它会很好用的.

希望这有帮助!!

Mongodb相关问答推荐

如何获取键值对的对象,其中值仅具有 mongoDB 中的投影字段

MongoDB - 将数组元素转换为新字段

mongodb.将文档分组在数组中,对它们进行评分计数和求和并添加新字段

Golang 无法在 MongoDB 中创建文档

Mongodb,在一个查询中用正则表达式更新部分字符串

如何使用指南针连接到 mongodb replicaset (k8s)

根据聚合管道MongoDB Atlas触发器中的条件更新多个字段

MongoDB中的readPreference和readConcern有什么区别?

使用 Flask-pymongo 扩展通过 _id 在 MongoDB 中搜索文档

Mocking/stubbing mongoose模型保存方法

如何在 MongoDb 中使用杰克逊将日期字段存储为 ISODate()

如何使用 Node.js 和 mongoose 解决command find requires authentication?

从 LinkedHashMap 转换为 Json 字符串

如何从 node.js 以编程方式执行 mongodump 命令?

如果我在 MongoDB 上使用 LINQ,为什么会失go 性能?

将 MongoCursor from ->find() 转换为数组

如何在 Meteor 应用程序之间共享 MongoDB 集合?

如何在 $match 内的 mongodb 聚合查询中使用 $regex

MongoDB:聚合框架: $match between fields

PyMongo 创建具有 2 个或更多字段的唯一索引