Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

>Solution :

require is Correct Not requrie

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading