Primes.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

server.js 566B

12345678910111213141516171819202122232425
  1. #!/usr/bin/env node
  2. var http = require("http");
  3. var fs = require("fs");
  4. var CPrime = require("./js/cprime");
  5. var maxnum = "9223372036854775806";
  6. var cprime = new CPrime(maxnum);
  7. var port = parseInt(process.argv[2]);
  8. if (isNaN(port)) {
  9. console.log("Usage: "+process.argv[1]+" <port>");
  10. process.exit(1);
  11. }
  12. var html = fs.readFileSync("index.html");
  13. http.createServer((req, res) => {
  14. if (req.url.indexOf("/factor/") === 0) {
  15. var num = req.url.substr("/factor/".length);
  16. cprime.factor(num, str => res.end(str));
  17. } else {
  18. res.end(html);
  19. }
  20. }).listen(port);