http.createServer永远不会调用callback | Node.js的

时间:2016-05-05 13:12:57

标签: javascript node.js http server

我正在使用Node.js项目并尝试使用http模块。

目前我有以下代码:

http.createServer(function(req, res){
    console.log("here!!!!"); 
});

这永远不会输出到控制台。为了进一步测试,我在console.log("here!!!!");上放置了一个断点。断点从未被击中。然后我在http.createServer(function(req, res){上设置断点。该程序确实在此断点处停止。踩到它表明它不会进入回调,而是完全跳过它。

任何想法会导致什么?

详细说明:

  

app.js

var express = require('express'); 
var app = express(); 

app.set('view engine', 'jade');
app.use(express.static(__dirname + '/public')

app.get('/map', function(req, res){
    res.render('view', {type: "block", name: req.query.name, latitude: req.query.latitude, longitude: req.query.longitude, zoom: req.query.zoom}); 
}); 

//Occurs when the picture is requested
app.get(/^\/omb\/1.0.0\/(.+)\/(.+)\/(.+)\/(.+)\.[a-zA-Z]*$/, function(req, res){
    var MosaicStreamer = require('./models/MosaicStreamer.js'); 
    var ms = new MosaicStreamer; 
    var configs = {library: req.params[0], zoom: req.params[1], column: req.params[2], row: req.params[3]}; 
    ms.handleTile(configs); 
});

app.listen(3000, function(){
    console.log('Tile Server listening on port 3000...'); 
});

1 个答案:

答案 0 :(得分:0)

让我复制&粘贴来自NodeJS documentation的代码 - 您错过了.listen()来电。

'use strict';

const http = require('http');

const server = http.createServer((req, res) => {
  console.log(req)
  res.end();
});

server.listen(8000);