简体   繁体   English

Node.js:错误:ENOENT:没有这样的文件或目录

[英]Node.js: Error: ENOENT: no such file or directory

I keep getting this message when I'm trying to connect to localhost:3000 (Visual Studio Code, Node JS).当我尝试连接到 localhost:3000(Visual Studio Code,Node JS)时,我不断收到此消息。 I am not sure how to correct this.Edit: I corrected my file to server.js but I am still getting the same message.我不确定如何更正。编辑:我将文件更正为 server.js,但我仍然收到相同的消息。 Any help is appreciated任何帮助表示赞赏在此处输入图像描述!

Here is my code for server.js这是我的 server.js 代码

const express = require('express');
const path = require('path');

let initial_path = path.join(__dirname, "public");

const app = express();
app.use(express.static(initial_path));

app.get('/', (req, res) => {
    res.sendFile(path.join(initial_path, "home.html"));
})

app.listen("3000", () => {
    console.log('listening......');
})

And my code for package.json还有我的 package.json 代码

{
  "name": "bloggin-site",
  "version": "1.0.0",
  "main": "server.js",
  "scripts": {
    "start": "nodemon server.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express-fileupload": "^1.2.1",
    "express.js": "^1.0.0",
    "nodemon": "^2.0.15"
  },
  "devDependencies": {},
  "description": ""
}

It's going to be a lot of little error like this as you learn.在你学习的过程中,会出现很多这样的小错误。 Try to slow down and read.试着放慢速度阅读。 Your filename is servor.js你的文件名是servor.js 在此处输入图像描述

rename servor.js to server.js .servor.js重命名为server.js I faced a lot when I am learning programming) Good luck bro keep it up!我在学习编程时遇到了很多问题)祝兄弟继续努力!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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