javascript - Node js file execution -
i having sample node js file executed in command prompt, but, not coming in browser,
var http = require('http'); port = process.argv[2] || 8888; http.createserver(function(request,response){ response.writehead(200, { 'content-type': 'text/html' }); var pi = math.pi; exports.area = function (r) { var res1 = pi * r * r; response.end(res1, 'utf-8'); // alert(res1); return res1; }; exports.circumference = function (r) { var res2 = 2 * pi * r; response.end(res2, 'utf-8'); //alert(res2); return res2; }; }).listen(parseint(port, 10)); console.log("file server running at\n => hostname " + port + "/\nctrl + c shutdown");
strong text can anyone, please tell me have done mistake
the problem not writing response of request.
response.write()
also using methods alert();
browser methods, code run executed in server side.
currently declare methods not call out anything.
this example should work:
var http = require('http'); port = process.argv[2] || 8888; http.createserver(function(request, response) { response.writehead(200, { 'content-type': 'text/html' }); var pi = math.pi; area = function(r) { var res1 = pi * r * r; response.write('area = ' + res1); // alert(res1); return res1; }; circumference = function(r) { var res2 = 2 * pi * r; response.write('circumference = ' +res2); //alert(res2); return res2; }; area(32); response.write(' '); circumference(23); response.end(); }).listen(parseint(port, 10)); console.log("file server running at\n => hostname " + port + "/\nctrl + c shutdown");
Comments
Post a Comment