0

I building socket.io app using express, originally had all CSS/JS in index.html and used

var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);

app.get('/', function(req, res){
  res.sendfile('index.html');
});

but now I split CSS/JS to seperate files app.css and app.js but when I start the app and visit page in Console Log in browser I get

Failed to load resource errors for the CSS/JS, what should I do so it also allows seperate CSS/JS?

1 Answer 1

1
var express = require('express'),
     app = express(),
     http = require('http').Server(app),
     io = require('socket.io')(http);

app.use(express.static(__dirname + '/public'));
http.listen(port);

index.html will be displayed at http://localhost:[port].

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

Comments

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.