2
votes

``

This is my code for running Node js file system


    var http = require('http');
    var fs = require('fs');
    http.createServer(function (req, res) {
      //Open a file on the server and return its content:
      fs.readFile('demofile1.html', function(err, data) {
        res.writeHead(200, {'Content-Type': 'text/html'});
        res.write(data);
        return res.end();
     
 });
    }).listen(3000);


``

> This is the error iam facing while running the code

internal/modules/cjs/loader.js:985 throw err; ^enter code here Error: Cannot find module 'C:\Users\DELL\Desktop\node js programs\file' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:982:15) at Function.Module._load (internal/modules/cjs/loader.js:864:27) at Function.executeUserEntryPoint [as runMain] ( { code: 'MODULE_NOT_FOUND', requireStack: [] }

4
Welcome to Stack Overflow. Please take the tour and read the information guides in the help center help center. Users are much more likely to help if you (1) show some research effort on your own (Google and StackOverflow searches), (2) learn what are appropriate questions for this forum, (3) show your images and (4) provide a minimal, complete, and verifiable example to your specific problem.pradosh nair

4 Answers

3
votes

Do you have a folder in your project node_modules?

I suspect you don't. Please run npm install in your project directory.

3
votes

For me this error occurred due to incorrect path specified. Initially, I was trying this path

"C:\Users\abc\Documents\VS CODE\JS> node basic.js"   

but the actual path was

"C:\Users\abc\Documents\VS CODE\JS\demo> node basic.js"

Check if you have the correct path of your file. As when you open your vscode, the terminal is set to your workspace folder not for the folder where your files actually are.

NOTE:

  1. Delete npm and npm-cache folder from C:\Users\appdata\roaming

  2. Add "C:\Program Files\nodejs\node_modules\npm" to your path variable.

0
votes

This error occurs when you have specified the wrong path. Check your directory in which you are executing

-1
votes

This error generally occurs If you require some modules or files, which do not exists in that specified path, Please check for your required modules/imports.