简体   繁体   中英

http.createServer never calling callback | Node.js

I'm working on a Node.js project and am attempting to use the http module.

Currently I have the following code:

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

This never outputs to the console. To test further, I placed a breakpoint on console.log("here!!!!"); . The breakpoint was never hit. I then set a breakpoint on http.createServer(function(req, res){ . The program did stop at this breakpoint. Stepping over showed that it then does not go into the callback but instead skips over it completely.

Any idea what would cause this?


Details:

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...'); 
});

Let me copy & paste code from NodeJS documentation - you miss .listen() call.

'use strict';

const http = require('http');

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

server.listen(8000);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM