[英]Install node.js and mongoDB on Cubietruck
I have installed Cubian OS on my Cubieboard . 我已经安装Cubian在我的OS Cubieboard 。 Then I installed node.js and mongoDB using this tutorial .
然后,使用本教程安装了node.js和mongoDB。 It seems node.js is working properly.
看来node.js工作正常。 I can start mongod service but I have several problems:
我可以启动mongod服务,但是有几个问题:
npm install
produce a lots of errors and I can't install required modules using this command (but I still can use nmp install module_name
command) npm install
产生很多错误,我无法使用此命令安装所需的模块(但我仍然可以使用nmp install module_name
命令) My test node.js code: 我的测试node.js代码:
var express = require('express');
// Mongoose import
var mongoose = require('mongoose');
var db = mongoose.connection;
db.on('error', console.error);
db.once('open', function() {
// Create your schemas and models here.
console.log('Connected');
});
// Mongoose connection to MongoDB (ted/ted is readonly)
mongoose.connect('mongodb://127.0.0.1:27017/test', function (error) {
if (error) {
console.log(error);
}
});
// Mongoose Schema definition
var Schema = mongoose.Schema;
var UserSchema = new Schema({
first_name: String,
last_name: String,
email: String
});
// Mongoose Model definition
var User = mongoose.model('users', UserSchema);
// Bootstrap express
var app = express();
// URLS management
app.get('/', function (req, res) {
res.send("<a href='/users'>Show Users</a>");
});
app.get('/users', function (req, res) {
User.find({}, function (err, docs) {
res.json(docs);
});
});
app.get('/users/:email', function (req, res) {
if (req.params.email) {
User.find({ email: req.params.email }, function (err, docs) {
res.json(docs);
});
}
});
// Start the server
var server = app.listen(3000, function () {
var host = server.address().address
var port = server.address().port
console.log('Example app listening at http://%s:%s', host, port)
});
When I execute sudo node server.js
command I get following: 当我执行
sudo node server.js
命令时,我得到以下信息:
Example app listening at http://0.0.0.0:3000
[Error: failed to connect to [127.0.0.1:27017]]
As you can see the IP address is incorrect and localhost:3000 (127.0.0.1:3000) is unavailable too. 如您所见,IP地址不正确,并且localhost:3000(127.0.0.1:3000)也不可用。
Does anyone can help me? 有人可以帮助我吗? Thanks!
谢谢!
I've added the following lines to /etc/network/interfaces and after that my web-site became available: 我在/ etc / network / interfaces中添加了以下几行,之后我的网站可用:
auto lo
iface lo inet loopback
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.