找到你要的答案

Q:How to install NodeJS + MongoDB on ec2 Amazon server

Q:如何在EC2亚马逊服务器安装Nodejs + MongoDB

I don't have much knowledge about mongo and NodeJS, and also about server set up so I might be asking something basic.

I'm trying to install MongoDB and NodeJS for school project. In order to do so I registered to Amazon EC2 server and implemented an instance according to some tutorials I've found on line. Using MongoDB wiki, I've installed Mongo on the server and using another Tutorial I installed NodeJS.

Just to be super clear, please see below picture who's showing the directory and MongoDB server listening:

http://s23.postimg.org/k02f747m2/mongo_Dir.jpg

After I've done that I'm trying to start using the server, I've created a simple file using the following code:

var mongodb = require('mongodb');
var server = new mongodb.Server('127.0.0.1', 27017, {});
var client = new mongodb.Db('exampledb', server, {w: 1});

client.open(function(err) {
  if (err) throw err;
  client.collection('students', function(err, collection) {
    if (err) throw err;

    collection.insert(
      {
        "name": "Noam",
        "year": "2012."
      },
      {safe: true},
      function(err, documents) {
        if (err) throw err;
        console.log('Document ID is: ' + documents[0]._id);
      }
    );
  });
}); 

Now I tried to run the file and received the following error

http://s30.postimg.org/sqplfazlt/eror.jpg

Any help?

我没有太多关于芒果和Nodejs知识,也关于服务器设置所以我会问一些最基本的东西。

I'm trying to install MongoDB and NodeJS for school project. In order to do so I registered to Amazon EC2 server and implemented an instance according to some tutorials I've found on line. Using MongoDB wiki, I've installed Mongo on the server and using another Tutorial I installed NodeJS.

只是要超清晰,请看下面的图片是显示目录和MongoDB服务器侦听:

http://s23.postimg.org/k02f747m2/mongo_dir.jpg

在我做了,我试图开始使用服务器,我已经创建了一个简单的文件使用下面的代码:

var mongodb = require('mongodb');
var server = new mongodb.Server('127.0.0.1', 27017, {});
var client = new mongodb.Db('exampledb', server, {w: 1});

client.open(function(err) {
  if (err) throw err;
  client.collection('students', function(err, collection) {
    if (err) throw err;

    collection.insert(
      {
        "name": "Noam",
        "year": "2012."
      },
      {safe: true},
      function(err, documents) {
        if (err) throw err;
        console.log('Document ID is: ' + documents[0]._id);
      }
    );
  });
}); 

现在我试图运行文件,并收到了以下错误

http://s30.postimg.org/sqplfazlt/eror.jpg

任何帮助吗?

node.js  mongodb  amazon-ec2