Home > front end >  Node.js: Error: ENOENT: no such file or directory
Node.js: Error: ENOENT: no such file or directory

Time:12-07

I keep getting this message when I'm trying to connect to 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. Any help is appreciatedenter image description here!

Here is my code for 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

{
  "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": ""
}

CodePudding user response:

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 enter image description here

CodePudding user response:

rename servor.js to server.js. I faced a lot when I am learning programming) Good luck bro keep it up!

  • Related