Node.js serve HTML, but can't load script files in served page
You're able to use it, but you need to serve that javascript file from your server through a valid path.
In your HTML you're trying to retrieve the javascript file from /client/client.js
The hint here is:
Imagine the following URL of your server http://myserver:8080/
Now, your HTML is trying to retrieve the js file through http://myserver:8080/client/client.js
As you can see, your server is not serving that assets, thus you won't be able to retrieve that js file.
Do the following:
app.get('/client/client.js', function(req, res) {
res.sendFile(path.join(__dirname + '/client.js'));
});
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname + '/client/index.html'));
});
Create a virtual path.
app.use('/client', express.static(path.join(__dirname, 'client')));