Confused with the given node.js code



Hello! When creating a new node.js project, in the index.html file it references like so

script src="/"

However in the file directory, I don’t see any path that leads to that folder? How does the index.html get the file?

The reason I’m asking is because I’m trying to use in my own app and it keeps giving me on my browser console

GET 404 (Not Found)

on the server side, I have this setup

var express     = require('express');
var app         = express();
var server      = require('http').createServer(app);
var port        = process.env.PORT || 3000;
var hostname    = process.env.IP || "";
var io          = require('').listen(server);
var path        = require('path');

app.get('/', function(req, res) {
   res.sendFile(path.join(__dirname + '/client/index.html'));

app.use('/client', express.static(__dirname + '/client'));
app.use(express.static(path.resolve(__dirname, 'client')));

app.listen(port || hostname, function () {
    console.log('Running the server on port ' + port);

var needSupport = [];
var finishedTasks = [];

io.on('connection', function (socket) {
  console.log("socket connected");

and on the index.html file i have this.

<script src=""></script>
var socket = io.connect());

socket.on('connect', function () {

Can you help me out on why it’s not working? Thank you! I’m guessing it has to do something with me not having the http server listen to a port. I want to use express to make my web app though


Okay found the problem. For one I had to use server.listen. Another thing is that I had to update the server to match the client socket. At least that’s what I think is the problem. It works now :slight_smile: