简体   繁体   English

终端卷曲:(7)无法连接到localhost端口3000:连接被拒绝

[英]Terminal curl: (7) Failed to connect to localhost port 3000: Connection refused

I am using OSX Elcapitan, 10.11.6, when I run 当我跑步时,我正在使用OSX Elcapitan,10.11.6

curl localhost:3000

or 要么

curl localhost:3000 -4

or 要么

curl 0.0.0.0:3000

or 要么

curl -x "" "http://127.0.0.1:3000"

It always says: 它总是说:

curl: (7) Failed to connect to 127.0.0.1 port 3000: Connection refused curl:(7)无法连接到127.0.0.1端口3000:连接被拒绝

ruby -v

ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-darwin13.0] ruby 2.1.3p242(2014-09-19修订版47630)[x86_64-darwin13.0]

my code: 我的代码:

var http = require('http'),
    express = require('express'),
    path = require('path'),
    MongoClient = require('mongodb').MongoClient,
    Server = require('mongodb').Server,
    CollectionDriver = require('./collectionDriver').CollectionDriver;

var app = express();
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({extended: false}));

var mongoHost = 'localHost';
var mongoPort = 27017;
var collectionDriver;

var url = 'mongodb://localhost:27017/mongo-server';
// Use connect method to connect to the server
MongoClient.connect(url, function(error, db) {
  if (error) {
    console.error(error.message);
    process.exit(1);
  }

  console.log("Connected to MongoDB successfully.");
  collectionDriver = new CollectionDriver(db);
});

app.use(express.static(path.join(__dirname, 'public')));

app.get('/', function (req, res) {
  res.send('<html><body><h1>Hello World</h1></body></html>');
});

app.get('/:collection', function(req, res) {
   var params = req.params;
   collectionDriver.findAll(req.params.collection, function(error, objs) {
          if (error) { res.send(400, error); }
          else {
              if (req.accepts('html')) {
                  res.render('data',{objects: objs, collection: req.params.collection});
              } else {
              res.set('Content-Type','application/json');
                  res.send(200, objs);
              }
         }
    });
});

app.get('/:collection/:entity', function(req, res) {
   var params = req.params;
   var entity = params.entity;
   var collection = params.collection;
   if (entity) {
       collectionDriver.get(collection, entity, function(error, objs) {
          if (error) { res.send(400, error); }
          else { res.send(200, objs); }
       });
   } else {
      res.send(400, {error: 'bad url', url: req.url});
   }
});

app.post('/:collection', function(req, res) {
    var object = req.body;
    var collection = req.params.collection;
    collectionDriver.save(collection, object, function(err,docs) {
          if (err) { res.send(400, err); }
          else { res.send(201, docs); }
     });
});

app.put('/:collection/:entity', function(req, res) {
    var params = req.params;
    var entity = params.entity;
    var collection = params.collection;
    if (entity) {
       collectionDriver.update(collection, req.body, entity, function(error, objs) {
          if (error) { res.send(400, error); }
          else { res.send(200, objs); }
       });
   } else {
       var error = { "message" : "Cannot PUT a whole collection" }
       res.send(400, error);
   }
});

app.delete('/:collection/:entity', function(req, res) {
    var params = req.params;
    var entity = params.entity;
    var collection = params.collection;
    if (entity) {
       collectionDriver.delete(collection, entity, function(error, objs) {
          if (error) { res.send(400, error); }
          else { res.send(200, objs); }
       });
   } else {
       var error = { "message" : "Cannot DELETE a whole collection" }
       res.send(400, error);
   }
});

app.use(function (req,res) {
    res.render('404', {url:req.url});
});

http.createServer(app).listen(app.get('port'), function(){
  console.log('Express server listening on port ' + app.get('port'));
});

It looks like you didn't start your server, or it's running on a port other than the one you're expecting. 看起来你没有启动你的服务器,或者它运行在你期望的端口以外的端口上。

If this is a Rails app, rails c gets it going. 如果这是一个Rails应用程序, rails c就可以了。 If it's some other Rack based program you'll need to launch it another way, like with Pow . 如果是其他基于Rack的程序,你需要以另一种方式启动它,就像使用Pow一样

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 连接被拒绝 - “localhost”端口 25 rails 的 connect(2) - Connection refused - connect(2) for "localhost" port 25 rails 连接被拒绝 - 使用DigitalOcean连接(2)“localhost”端口9200 - Connection refused - connect(2) for “localhost” port 9200 with DigitalOcean Errno :: ECONNREFUSED(连接被拒绝-“ localhost”端口587的connect(2))操作邮件 - Errno::ECONNREFUSED (Connection refused - connect(2) for “localhost” port 587) action mailer 连接被拒绝 - “本地主机”端口 1025 的连接(2) - 设计邮件程序 - Connection refused - connect(2) for "localhost" port 1025 - Devise Mailer 连接失败:localhost(Errno :: ECONNREFUSED:连接被拒绝 - 连接(2)) - connection failed for: localhost (Errno::ECONNREFUSED: Connection refused - connect(2)) Seahorse :: Client :: NetworkingError:连接被拒绝-“ localhost”端口8000的connect(2) - Seahorse::Client::NetworkingError: Connection refused - connect(2) for “localhost” port 8000 法拉第:: ConnectionFailed,连接被拒绝 - 连接(2)为“localhost”端口9200错误Ruby on Rails - Faraday::ConnectionFailed, Connection refused - connect(2) for “localhost” port 9200 Error Ruby on Rails Errno :: ECONNREFUSED(无法打开TCP连接到:80(连接被拒绝 - 连接(2)nil端口80)) - Errno::ECONNREFUSED (Failed to open TCP connection to :80 (Connection refused - connect(2) for nil port 80)) Rails 2.3.9和SendGrid,连接被拒绝 - 在localhost上连接(2) - Rails 2.3.9 and SendGrid, Connection refused - connect(2) on localhost ssh:连接到主机heroku端口22:连接被拒绝 - ssh: connect to host heroku port 22: Connection refused
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM