0

My app.js file looks like this, I am trying to have my root point to a tic tac toe game.

app.set('port', (process.env.PORT || 5000))


//serve static files in the public directory
app.use(express.static('public'));

// Process application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({
extended: false
}))

// Process application/json
app.use(bodyParser.json())

// Index route
app.get('/', function (req, res) {
res.sendFile('index.html',{root:"./Tic-Tac-Toe"});


})

In my index.html in the ./Tic-Tac-Toe dir, I am linking some files that cannot seem to be found by the server.

<link rel = 'stylesheet' type = 'text/css' href = 'ui.css'>
<script src = "jquery-1.10.1.min.js"></script>
<script src = "ui.js"></script>
<script src = "game.js"></script>
<script src = "ai.js"></script>
<script src = "control.js"></script>

I get these errors in my console. enter image description here

1
  • Can you post your file structure, will be helpful when trying to debug what is happening here Commented Nov 22, 2016 at 19:24

1 Answer 1

1
app.use(express.static(path.join(__dirname, 'public')));

Try above line instead of

app.use(express.static('public'));
Sign up to request clarification or add additional context in comments.

4 Comments

path is a npm module.
I added app.use(express.static(path.join(__dirname, 'public'))); instead of app.use(express.static('public')); Did not work.
I get the same I had before in the console.
<link rel = 'stylesheet' type = 'text/css' href = '/ui.css'> <script src = "/jquery-1.10.1.min.js"></script> <script src = "/ui.js"></script> <script src = "/game.js"></script> <script src = "/ai.js"></script> <script src = "/control.js"></script>

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.