Node js failed to load resource the server responded with a status of 404 Not Found

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:50:03+00:00 2022-08-01T02:50:03+00:00

763

Hope u all are doing fine. My question is anycodings_javascript that whenever i am trying to create a anycodings_javascript navigation bar and serve that navigation bar anycodings_javascript on my server it is responding with error 404 anycodings_javascript not found, but i have placed my logo file in anycodings_javascript the same directory where my code is the html anycodings_javascript 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_javascript 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_node.js static files. According to it's doc - anycodings_node.js something like:

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

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

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

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

(Instead of var app = anycodings_node.js require('express')();)

0

2022-08-01T02:50:03+00:00 2022-08-01T02:50:03+00:00Answer Link

mRahman

3

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_node.js the same folder where the other files anycodings_node.js are present you can try to use it this anycodings_node.js way.

express.static(__dirname).

0

2022-08-01T02:50:03+00:00 2022-08-01T02:50:03+00:00Answer Link

miraj