从零开始学习Node.js系列教程四:多页面实现的数学运算示例

前端之家收集整理的这篇文章主要介绍了从零开始学习Node.js系列教程四:多页面实现的数学运算示例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

本文实例讲述了Node.js多页面实现的数学运算。分享给大家供大家参考,具体如下:

app-node.js

404,{'Content-Type': 'text/plain'}); res.end("bad URL" + req.url); } }); server.listen(http_port); console.log('listening to http://localhost:3000');

htutil.js

"].join('\n'); } exports.page = function(title,navbar,content){ return ["{title}","

{title}

","" ].join('\n') .replace(new RegExp("{title}","gm"),title) .replace("{navbar}",navbar) .replace("{content}",content); }

home-node.js

Math Wizard

")); }

square-node.js

{a} squared = {sq}

" .replace("{a}",req.a) .replace("{sq}",req.a * req.a)) : ""),"

Enter numbers to see its square

","
","A:
","","
" ].join('\n')) ); }

factorial-node.js

{a} factorial = {fact}

" .replace("{a}",req.a) .replace("{fact}",math.factorial(Math.floor(req.a)))) : ""),"

Enter numbers to see its factorial

","
","
" ].join('\n')) ); }

mult-node.js

{a} * {b} = {result}

" .replace("{a}",req.a) .replace("{b}",req.b) .replace("{result}",req.a * req.b)) : ""),"

Enter numbers to mutiply

","
","B:
","
" ].join('\n')) ); }

fibo-node.js

{a} fibonacci = {fibo}

" .replace("{a}",Math.floor(req.a)) .replace("{fibo}",math.fibonacci(Math.floor(req.a)))) : ""),"

Enter numbers to see its fibonacci

","
","
" ].join('\n')) ); }

fibo2-node.js

{a} fibonacci = {fibo}

" .replace("{a}",a) .replace("{fibo}",fiboval)) : ""),"" ].join('\n')) ); } exports.get = function(req,res){ if (!isNaN(req.a)){ math.fibonacciAsync(Math.floor(req.a),function(val){ sendResult(req,Math.floor(req.a),val); }); }else { sendResult(req,NaN,NaN); } }

math.js

希望本文所述对大家nodejs程序设计有所帮助。

猜你在找的Node.js相关文章