简体   繁体   中英

Starting node.js, getting confusing results

I'm currently diving into node.js stuff starting with very simple examples.

The following code is not really a big deal but already confuses me:

require('http')
    .createServer( function( req, res ) {
        console.log( 'receiving request' );
        res.end( 'end' );
    } )
    .listen( 1337, "localhost" );

After having started the server via console I called http://localhost:1337 In the console I got the "receiving request"-message two times not one time as expected.

What is this all about? Did I already mess this easy thin up?

Browsers will automatically make a call to /favicon.ico when requesting a page. Your node server responds to both the "page" request and the "favicon.ico" request. Hence the two log lines.

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