2019-12-16
20:12:38
require('http').createServer(function(req,res){ res.writeHead(200,{'Content-Type':'text/html'}); res.end('<h1>Hello World</h1>'); }).listen(3000);
/** * Module dependencies. */ var net = require('net') /** * Create server. */ var server = net.createServer(function (conn) { // handle connection console.log(' 33[90m new connection! 33[39m'); }); /** * Listen. */ server.listen(3000, function () { console.log(' 33[96m server listening on *:3000 33[39m'); });
/** * Module dependencies. */ var net = require('net') /** * Keep track of connections. */ var count = 0; /** * Create server. */ var server = net.createServer(function (conn) { conn.write( ' > welcome to 33[92mnode-chat 33[39m!' + ' > ' + count + ' other people are connected at this time.' + ' > please write your name and press enter: ' ); count++; conn.on('close', function () { count--; }); }); /** * Listen. */ server.listen(3000, function () { console.log(' 33[96m server listening on *:3000 33[39m'); });