0

I am making an app with socket.io, so right now I'm making the user interface with HTML and CSS, and everything is working except that when I try to use the nav to go back to the index.html it can't get it. The other Nav elements work because they are in the public directory, but if I move the index file to the public directory it will say that it can't find an index.html at all. So, my main question is, how do I get it to be able to find the HTML file, not in the public directory or to get it to find the index file in the public directory to start off with?

File Structure:

index.html
server.js
public
   settings.html
   friends.html

HTML for nav:

        <nav>
            <ul>
                <li><a href="http://localhost:5000/index.html" >Chat</a></li>
                <li><a href="http://localhost:5000/friends.html">Friends</a></li>
                <li><a href="http://localhost:5000/settings.html">Settings</a></li>
            </ul>
        </nav>

Relevant JS:

var express = require('express');
var app = express();
app.use(express.static('public'))
2
  • 2
    You gotta move your index.html inside public directory. Commented Oct 8, 2018 at 15:27
  • 1
    If you ever plan to make this site accessible over the Internet, you should change your "localhost:5000..." links to just "/index.html" and "/friends.html", etc. Commented Oct 8, 2018 at 15:29

1 Answer 1

4

how do I get it to be able to find the html file not in the public directory

You need to either:

  • Make your static route look in the root directory instead of the public directory (not a good idea because you have server code there)
  • Set up another static route (ditto)
  • Write an explicit get handler for / which has code which reads index.html and returns it
Sign up to request clarification or add additional context in comments.

1 Comment

It works fine for me by having index.html inside the public directory as stated by Praveen

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.