http.createServer(function (req, res) { var url = URL.parse(req.url); res.writeHead(200, { 'Content-Type': 'text/html' }); res.end(fs.readFileSync(__dirname + url.pathname)); })
http.createServer(function (req, res) { var url = URL.parse(req.url, true), uri = decodeURIComponent(url.pathname), postData = ''; if (paths[uri] !== undefined) { if (req.method === 'POST') { req.on('data', function (chunk) { postData += chunk.toString(); }); req.on('end', function () { if (!req.headers['content-type'] || req.headers['content-type'].indexOf('multipart') !== 0) postData = qs.parse(postData); paths[uri](url, req, res, postData); }); } else { paths[uri](url, req, res); } } else { res.writeHead(404); res.end(); } })
if (enableTls) { this.redirector = http.createServer((req, res) => { res.writeHead(301, { Location: `https://${req.headers.host.split(':')[0]}:${TLS_PORT}${req.url}` });
http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello Travis!\n'); }).listen(1337, '127.0.0.1');
http.createServer((req, res) => { // Send "Hello World" to every request res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Hello World'); })
http.createServer(function(req, res) { const query = url.parse(req.url, true).query; totalSales(query.item).then(function(sum) { res.writeHead(200); res.end(`Total sales for item ${query.item} is ${sum}`); }); }).listen(8000, function() {console.log('Started')});
http.createServer(function (request, response) { // 回调函数接收request和response对象 // 获得HTTP请求的method和url console.log(request.method + ': ' + request.url); // 设置response response.writeHead(200, { 'Content-Type': 'text/html' }); response.end('<h1>Hello world!</h1>'); })
proxy.on('error', function (err, req, res) { logger.error(err) res.writeHead(502, { 'Content-Type': 'application/json' }) return res.end(JSON.stringify({ error: 'Proxy error' })) })
require('http').createServer((req, res) => { res.writeHead(200); db.createValueStream() .pipe(JSONStream.stringify()) .pipe(res); }).listen(8090);
http.createServer(function(req, res){ res.writeHead(200, {'Content-Type': 'text/plain; charset=utf-8'}); // 解析 url 参数 var params = url.parse(req.url, true).query; res.write("name: " + params.name); res.write("\n"); res.write("url: " + params.url); res.end(); }).listen(8888);
https.createServer(options, (req, res) => { console.log(req.url); res.writeHead(200); res.end('hello world\n'); }).listen(6789);
http.createServer(function(request, response) { response.writeHead(200, {"Content-Type": "text/plain"}); response.write("Hello World"); response.end(); }).listen(8888);
https.createServer(httpsOptions, (req, res) => { // Send "Hello World" to every request res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Hello World'); })
https.createServer(options, (req, res) => { console.log(req.url); res.writeHead(200); res.end('hello world\n'); }).listen(6789);