1

I have this little Express.js calculator, that is supposed to pass variable routes depending on types of operation and operands are passed as variables too. However, an error is given.

var express = require("express");

var PORT = process.env.PORT || 8080;

var app = express();

let operation; let operand1; let operand2;

app.get(`/:operation/:operand1/:operand2`, function(req, res) {

  var result;

  switch (operation) {

  case "add":
    result=operand1+operand2;
    break;
  case "subtract":
    result=operand1-operand2;
    break;
  case "multiply":
    result=operand1*operand2;
    break;
  case "divide":
    result=operand1/operand2;
    break;
  default:
    result="Sorry! The only valid operations are add, subtract, multiply, and divide.";
  }


  res.send(result.toString());

});


app.listen(PORT, function() {

  console.log("Server listening on: http://localhost:" + PORT);
});

The error given by Node.js is

Error: Cannot find module 'C:\Users\19513\Desktop\In-Class-Exercises\calculator.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:282:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
OlegArsyonov
  • 981
  • 1
  • 9
  • 17

0 Answers0