Skip to content

Instantly share code, notes, and snippets.

@kaiquewdev
Created May 31, 2012 01:03
Show Gist options
  • Save kaiquewdev/2840008 to your computer and use it in GitHub Desktop.
Save kaiquewdev/2840008 to your computer and use it in GitHub Desktop.
Servidor http simples usando node.js
// 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