Failed to load resource: the server responded with a status of 404 not Found MongoDB

Error while doing node js: Failed to load resource: the server responded with a status of 404 (Not Found)

Questions : Error while doing node js: Failed to load resource: the server responded with a status of 404 (Not Found)

2022-08-01T02:40:48+00:00 2022-08-01T02:40:48+00:00

763

Hope u all are doing fine. My question is anycodings_node.js that whenever i am trying to create a anycodings_node.js navigation bar and serve that navigation bar anycodings_node.js on my server it is responding with error 404 anycodings_node.js not found, but i have placed my logo file in anycodings_node.js the same directory where my code is the html anycodings_node.js code is:-

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Discord Chat</title> <link href="https://fonts.googleapis.com/css2?family=Karla&display=swap" rel="stylesheet"> <link rel="icon" href="logo.png"> <style> * { margin: 0px; padding: 0px; font-family: 'Karla', sans-serif; } #logo { width: 50px; height: 50px; border-radius: 30px; } .navbar ul{ position: sticky; } .navbar ul li a{ text-decoration: none; text-transform: none; color: lightseagreen; } .navbar ul li{ list-style: none; display: inline; position: relative; top: -30px; left: 71px; padding: 20px; } .navbar{ background-color: black; opacity: 0.6; } .navbar ul li:hover { cursor: pointer; border-radius: 50px; animation-name: navanim; animation-duration: 5s; animation-iteration-count: 1; font-size: 20px; } @keyframes navanim{ from{ background-color: white; color: black; } to{ background-color: black; color: white; } } </style> </head> <body> <nav class="navbar"> <img src="logo.png" alt="Discord Chat" id="logo"> <ul> <li><a href="index.html">Home</a></li> <li><a href="about.html">About</a></li> </ul> </nav> </body> </html>

and my server side code is:

var app = require('express')(); var http = require('http').Server(app); const port = 8000; app.get('/', (req, res) => { res.sendfile('index.html'); }); http.listen(port, function(){ console.log(`Server is listening on https://127.0.0.1:${port}/ `); });

any ideas from which i can display my logo anycodings_node.js in my web

Total Answers 2

32

Answers 1 : of Error while doing node js: Failed to load resource: the server responded with a status of 404 (Not Found)

You'll need to set up express to serve anycodings_javascript static files. According to it's doc - anycodings_javascript something like:

app.use(express.static('public'))

Would serve files from a directory anycodings_javascript 'public' relative to where the code anycodings_javascript is. More information is available at anycodings_javascript https://expressjs.com/en/starter/static-files.html.

You will need to not shortcut the import anycodings_javascript of express. So the first lines of your anycodings_javascript code should have:

const express = require('express') const app = express()

(Instead of var app = anycodings_javascript require('express')();)

0

2022-08-01T02:40:48+00:00 2022-08-01T02:40:48+00:00Answer Link

mRahman

1

Answers 2 : of Error while doing node js: Failed to load resource: the server responded with a status of 404 (Not Found)

Since you are keeping your logo file in anycodings_javascript the same folder where the other files anycodings_javascript are present you can try to use it this anycodings_javascript way.

express.static(__dirname).

0

2022-08-01T02:40:48+00:00 2022-08-01T02:40:48+00:00Answer Link

jidam

How to fix the server responded with a status of 404 not found?

The only way to fix this is to make sure that the CSS and JS files are properly linked within the HTML. Check whether the folder, file and directory name of these files are spelt correctly. Another way to fix this is by using an absolute URL instead of a relative URL.

What does failed to load resource the server responded with a status of 404 not found mean?

As mentioned, a 404 Not Found Error indicates that the client (web browser) is receiving a message from the server (remote computer) that the specific resource (web page/URL) is unavailable.