Created
May 31, 2012 01:03
-
-
Save kaiquewdev/2840008 to your computer and use it in GitHub Desktop.
Servidor http simples usando node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Servidor HTTP | |
var http = require( 'http' ); | |
var server = http.createServer( function ( request, response ) { | |
var body = { | |
type: 'text/plain', | |
content: 'Hello World!', | |
}; | |
response.writeHead( 200, { | |
'Content-Length': body.content.length, | |
'Content-Type': body.type, | |
}); | |
response.end( body.content ); | |
}); | |
server.listen( 3000, '127.0.0.1', function () { | |
console.log( 'Servidor funcionando, ip 127.0.0.1 porta 3000... ' ); | |
var connections = setInterval( function () { | |
if ( server.connections > 0 ) { | |
console.log('Nenhuma conexão no momento.'); | |
} if ( server.connections === 0 ) { | |
console.log( '%s, conexões abertas.', server.connections ); | |
} | |
}, 1000); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment