Home > other >  ReferenceError: require is not defined (at node:internal/main/run_main_module:23:47) in Node.js
ReferenceError: require is not defined (at node:internal/main/run_main_module:23:47) in Node.js

Time:01-02

I am learning Node.js (Node.js v18.12.1) and started building my first server (backend app).

here is the code

const express = requrie("express");
const app = express();
const port = 3000;

app.get("/", function (req, res) {
 res.sendFile("index.html");  
});

app.listen(port, function () {
    console.log("Server is running on 3000");
    });
  

However, I am getting the following error when I provide the command node app.js in terminal

const express = requrie("express");
                ^

ReferenceError: requrie is not defined
    at Object.<anonymous> (C:\Users\harsh\OneDrive\Documents\Visual Studio 2022\Web Development\firstNodeServer\app.js:3:17)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47

Also this is my package.json

{
  "name": "firstnodeserver",
  "version": "1.0.0",
  "description": "This is my First Node Server",
  "main": "app.js",
  "type": "commonjs",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Harshad Tekwani",
  "license": "ISC",
  "dependencies": {
    "express": "^4.18.2",
    "jshint": "^2.13.6",
    "nodemon": "^2.0.20"
  }
}

Please help me with respect to resolving this error.

I was trying to run the server at localhost:3000 which should have given me on my home route the index.html but instead I am getting the above error.

CodePudding user response:

require is Correct Not requrie

  • Related