admin管理员组文章数量:1429953
I have my project at desktop. And i have deleted the node_modules folder and reinstall it. But it is not working. Please help me resolve it. I have tried other methods on stack-overflow but they are not working for me i don't know whats wrong. Please help for sake of my final project. my folder setup:
Ols
+--app.js
+--package.json
+--package-lock.json
+--views
+--allejs
+--public
+--cs
+---images
+node_modules
var express = require("express");
var app = express();
var bodyParser = require("body-parser");
app.use(express.static("public"));
mongoose.connect("mongodb://localhost/ols");
app.use(bodyParser.urlencoded({extended: true}));
app.set("view engine", "ejs");
app.get("/", function(req, res) {
res.render("ols");
});
app.get("/home", function(req, res) {
res.render("ols");
});
app.get("/alLlaptops", function(req, res) {
res.render("allLaptops");
});
app.get("/contact", function(req, res) {
res.render("contact");
});
app.get("/signup", function(req, res) {
res.render("signup");
});
app.get("/login", function(req, res) {
res.render("login");
});
app.get("/addtocart", function(req, res) {
res.render("addtocart");
});
app.listen(3000, function() {
console.log("Server is listening!!!");
});
I have my project at desktop. And i have deleted the node_modules folder and reinstall it. But it is not working. Please help me resolve it. I have tried other methods on stack-overflow but they are not working for me i don't know whats wrong. Please help for sake of my final project. my folder setup:
Ols
+--app.js
+--package.json
+--package-lock.json
+--views
+--allejs
+--public
+--cs
+---images
+node_modules
var express = require("express");
var app = express();
var bodyParser = require("body-parser");
app.use(express.static("public"));
mongoose.connect("mongodb://localhost/ols");
app.use(bodyParser.urlencoded({extended: true}));
app.set("view engine", "ejs");
app.get("/", function(req, res) {
res.render("ols");
});
app.get("/home", function(req, res) {
res.render("ols");
});
app.get("/alLlaptops", function(req, res) {
res.render("allLaptops");
});
app.get("/contact", function(req, res) {
res.render("contact");
});
app.get("/signup", function(req, res) {
res.render("signup");
});
app.get("/login", function(req, res) {
res.render("login");
});
app.get("/addtocart", function(req, res) {
res.render("addtocart");
});
app.listen(3000, function() {
console.log("Server is listening!!!");
});
module.js:538
throw err;
^
Error: Cannot find module 'C:\Users\Haider Ali\Desktop\OLS\OLS\views\app.js'
at Function.Module._resolveFilename (module.js:536:15)
at Function.Module._load (module.js:466:25)
at Function.Module.runMain (module.js:676:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
Share
Improve this question
edited Mar 2, 2018 at 11:25
CopyPaste
asked Mar 2, 2018 at 10:08
CopyPasteCopyPaste
111 gold badge1 silver badge4 bronze badges
3
- Possible duplicate of NPM global install "cannot find module" – Anis D Commented Mar 2, 2018 at 10:10
-
Where are you running your start mand from in your file structure? It seems like you're inside the views directory, tried to run
node app.js
when in fact you need to be one level up. Can you give the print out of where you are in your directory structure, plus what all the files are inside that directory? – Elliot Blackburn Commented Mar 2, 2018 at 10:16 - structure is given in question – CopyPaste Commented Mar 2, 2018 at 11:26
1 Answer
Reset to default 1Check your package.json
file. It looks like your app.js
and the package.json
are not in the same folder.
{
"name": "final-project",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"start": "node app.js" // <--- node can't find app.js file
},
"keywords": [],
"author": "",
"license": "ISC"
}
You must change that to:
"scripts": {
"start": "./views/app.js" // or wherever app.js file is
}
本文标签: javascripthow to resolve can not find module in node jsStack Overflow
版权声明:本文标题:javascript - how to resolve can not find module in node js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745498843a2660934.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论