http.createServer(function(request, response) { response.writeHead(200, {"Content-Type": "text/plain"}); response.write("Hello World"); response.end(); }).listen(8888);
http.createServer((req, res) => { req.on('data', (chunk) => { const canContinue = res.write(chunk.toString().toUpperCase()) if (!canContinue) { req.pause() res.once('drain', () => req.resume()) } }) req.on('end', () => res.end()) })
(function (exports) { exports.customServer = function () { var http = require('http'); var server = http.createServer(function (req, res) { console.log(req.url); res.write("<html><body>hi</body></html>"); res.end(); }); server.listen(3000); } })(modules.exports);
http.createServer( function (request, response) { response.writeHead(HTTP_OK, header); response.write('<h1>Welcome to the World of Node Server!</h1>'); response.end(); })
http.createServer(function (req, res) { fs.readFile('./html/hello.html', function(err, data) { res.writeHead(200, {'Content-Type': 'text/html'}); var myUrl = req.url; var queryParam = url.parse(req.url, true).query; var txt = "nome="+queryParam.nome + "<br>" + "cognome="+queryParam.cognome; res.write(data + "<font size=\"2\"><p>"+myUrl+"</p></font>"); res.write("<font size=\"2\"><p>con i seguenti parametri</p>" + txt + " </font>"); res.end(); }); }).listen(8080);
http.createServer((req, res) => { const { query: { code } } = url.parse(req.url, true) if (code) { res.write(`<script>window.close()</script>`) process.send(code) } })
http.createServer(function(request, response) { var url = request.url; var parts = url.split('?'); var str = parts[1] || ''; response.writeHead(200, {'Content-Type':'text/plain'}); writeFile(__dirname + '/hello.txt', str) .then(function() { response.write('success'); response.end(); }); }).listen(3000);
http.createServer(function (request, response) { response.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'}); if(request.url!=="/favicon.ico"){ //清除第2次访问 console.log('访问'); response.write('hello,world'); //optfile.readfile("G:\\www\\nodejs\\one\\models\\aa.txt"); const data = optfile.readfileSync("./1.txt"); // 读文件 // response.write(data); // optfile.writeFileSync("./1.txt", 'dudu'); // 写文件 response.end();//不写则没有http协议尾 } }).listen(8000);
http.createServer(async (req, res) => { res.statusCode = 200 if (await streamLen(req) > 0) { res.write(JSON.stringify({ rate_by_service: { 'service:,env:': 1 } })) } res.end() }).listen(8126, 'localhost', () => { if (process.send) { process.send({ ready: true }) } })
http.createServer(function(request, response) { response.writeHead(200, {'Content-Type':'text/plain'}); co(function *() { var text = yield readFile(__dirname + '/hello.txt'); response.write(text + ' Tim!'); response.end(); }); }).listen(3000);
http.createServer(function (req, res) { fs.readFile('demoHtml.html', function (err, data) { res.writeHead(200,{'Content-Type':'text/html'}); res.write(data); res.end(); }); }).listen(8000);
http.createServer(function (request, response) { response.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'}); if(request.url!=="/favicon.ico"){ //清除第2此访问 console.log('访问'); response.write('hello,world'); response.end();//不写则没有http协议尾,但写了会产生两次访问 } }).listen(8000);
http.createServer(function(req,res){ fs.readFile('demofile1.html',function(err,data){ res.writeHead(200,{'Content-Type':'text/html'}); res.write(data); res.end(); }); }).listen(8080);
http .createServer(function(req, res) { res.writeHead(200, { 'Content-type': 'text/plain' }); res.write('hello world'); res.end(); }).listen(2016);