QueryStringFn.js

'use strict'; var http = require('http'); var url = require('url'); var querystring = require('querystring'); http.createServer(function(request, response) { var pathname = url.parse(request.url).pathname; var query = url.parse(request.url).query; var id = querystring.parse(query)['id']; var result = { 'pathname': pathname, 'id': id, 'value': Math.floor(Math.random() * 100) }; setTimeout(function() { response.writeHead(200, {"Content-Type": "application/json"}); response.end(JSON.stringify(result)); }, 2000 + Math.floor(Math.random() * 1000)); }).listen( 8080, function() { console.log('Echo Server listening on port 8080'); } );
Node JS Executing expensive asynchronous background tasks in parallel

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.