res.on('finish', function () { debug('Destroying response socket'); res.socket.destroy(); });
http .createServer((req, res) => { res.writeHead(200, { "Content-Type": "text/plain" }); while (chance.bool({ likelihood: 95 })) { res.write(chance.string() + "\n"); } res.end("\nThe end \n"); res.on("finish", () => { console.log("All data was sent"); }); }) .listen("8080", () => { console.log("Listening on 8080"); });
async function start() { // Instantiate nuxt.js const nuxt = new Nuxt(config) // Build in development if (config.dev) { const builder = new Builder(nuxt) await builder.build() } app.use(ctx => { ctx.status = 200 // koa defaults to 404 when it sees that status is unset return new Promise((resolve, reject) => { ctx.res.on('close', resolve) ctx.res.on('finish', resolve) nuxt.render(ctx.req, ctx.res, promise => { // nuxt.render passes a rejected promise into callback on error. promise.then(resolve).catch(reject) }) }) }) app.listen(port, host) consola.ready({ message: `Server listening on http://${host}:${port}`, badge: true }) }
res.on('finish',function(){ console.log('All data was sent'); });
res.on('close', function() { console.log("Connection closed!"); PubSub.unsubscribe(subscriber_token);
http.createServer((request, response) => { const { headers, method, url } = request; let body = []; request.on('error', (err) => { console.error(err); }).on('data', (chunk) => { body.push(chunk); }).on('end', () => { body = Buffer.concat(body).toString(); response.on('error', (err) => { console.error(err); });
require('http').createServer((req, res) => { // Write the head of the http response res.writeHead(200, { 'Content-Type': 'text/plain' }) // Start a loop that terminates with a likelihood of 5% while (chance.bool({ likelihood: 95 })) { // Write random string into the stream res.write(`${chance.string()}\n`) } // Once the loop terminates, call end on the stream // indicating that no more data will be written // Provide a final string to be written into the stream // Before ending it. res.end('\nThe end...\n') // Register a finish event, which will be fired when // all the data has been flushed into the underlying socket res.on('finish', () => { console.log('All data was sent') }) }).listen(8080, () => { console.log('Listening') })