简体   繁体   中英

i get this error.... Cannot find module 'async'

I'm using node Js Version 11.9.0 and my OS is windows 7 64bit i built App using mongoose module, as soon as i run my server.js i get the error Cannot find module 'async',

I'm sure async module already exist in my node modules folder i tried to install async globally i tried to require it.. var async = require("async")

var express = require("express");

var logger = require("morgan");

//var async =  require("async");

var mongoose = require("mongoose");

var PORT = 3000;


// Requiring the `User` model for accessing the `users` collection

var User = require("./userModel.js");

// Initialize Express

 var app = express();

// Configure middleware

// Use morgan logger for logging requests

app.use(logger("dev"));

// Parse request body as JSON

app.use(express.urlencoded({ extended: true }));

app.use(express.json());

// Make public a static folder

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

// Connect to the Mongo DB

mongoose.connect("mongodb://localhost/userdb", { useNewUrlParser: true });

// Routes

// Route to post our form submission to mongoDB via mongoose

app.post("/submit", function(req, res) {

  // Create a new user using req.body

   User.create(req.body).then(function(dbUser) {

  // If saved successfully, send the the new User document to the client

      res.json(dbUser);
    }).catch(function(err) {

      // If an error occurs, send the error to the client

      res.json(err);
    });
});

// Start the server

app.listen(PORT, function() {

  console.log("App running on port " + PORT + "!");

});


$ node server.js
internal/modules/cjs/loader.js:611
    throw err;
    ^

Error: Cannot find module 'async'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:609:15)
    at Function.Module._load (internal/modules/cjs/loader.js:535:25)
    at Module.require (internal/modules/cjs/loader.js:663:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (C:\Users\farahat\Desktop\mo\server.js:3:14)
    at Module._compile (internal/modules/cjs/loader.js:734:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:745:10)
    at Module.load (internal/modules/cjs/loader.js:626:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:566:12)
    at Function.Module._load (internal/modules/cjs/loader.js:558:3)

async installed globally. For that we have to create and install modules of async.

npm install async --save

this command line add files in node_modules folder.

Rerun npm install async . Are you sure you want to use the async module or do you just want to use async/await ? If the later, async is a language feature and you don't require any module for it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM