Sunday, March 15, 2020

Error: Cannot find module 'express'



Error Blog 

Hi Guys ,
This blog is about the error   Error: Cannot find module 'express'

Problem Statement

unable to run a file using node js .


Error Details 

error Log

ERROR DETAILS 
 Error: Cannot find module 'express'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> 
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)



Error Code 

Please validate the API endpoint .

  
     var express = require('express');
var app = express();

app.use(express.static('public'));

app.get('/'function (reqres) {
   res.send('Hello World');
})

var server = app.listen(8082function () {
   var host = server.address().address;
   var port = server.address().port;

   console.log("Example app listening at http://%s:%s"hostport)
})  
         

Solution

use npm install to install the required dependencies


Code Changes 

Install express

  
         npm install express
         
OUTPUT
node server.js     
Example app listening at http://:::8082




Thanks for reading . Let me know your thoughts in the comments below    .

No comments:

Post a Comment

ec2-user@ec2 Permission denied