我正在使用节点Js版本11.9.0,并且我的操作系统是Windows 7 64位,我使用mongoose模块构建了App,一旦运行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)
答案 0 :(得分:0)
重新运行payable_path
。您确定要使用npm install async
模块还是只想使用async
?如果是更高版本,则async/await
是一种语言功能,您无需为此async
的任何模块。
答案 1 :(得分:0)
异步已全局安装。为此,我们必须创建并安装异步模块。
@Service
此命令行在node_modules文件夹中添加文件。