1

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": "" } 
6
  • Rename servor.js to server.js. Spot the difference? Also, move server.js out of the public folder/directory. Commented Dec 7, 2021 at 4:14
  • @code thanks! I changed the name and my server.js file is out of the public folder and under Final but I am getting the same message. Any tips? Commented Dec 7, 2021 at 4:36
  • Do you get this error when you run node server.js or npm run start? The reason this error occurs is because the file is non-existent (likely because it's being referenced incorrectly). Commented Dec 7, 2021 at 4:39
  • I get it when I run npm start Commented Dec 7, 2021 at 4:44
  • Having changed the location of you file, you might want to double check your paths too. Commented Dec 7, 2021 at 4:49

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.