【发布时间】:2019-02-05 15:58:42
【问题描述】:
我使用的是节点 Js 版本 11.9.0,我的操作系统是 windows 7 64bit 我使用猫鼬模块构建了应用程序,一旦我运行我的 server.js,我就会收到错误找不到模块“异步”,
我确定我的节点模块文件夹中已经存在异步模块 我试图在全球范围内安装异步 我试图要求它.. 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? -
是的,显示你的 package.json 并检查 node_modules 中是否存在异步文件夹。
标签: node.js