Saturday, 10 June 2017

index.html not invoking javascript file

I'm making a simple client/server connection via node.js modules and a simple HTML page.

the html page is this:

<script type="text/javascript" src="index.js"></script>

Where the index.js file in the same directory is this:

alert("hello!");

This works fine when I manually click on the html page, but when I invoke it using my app.js:

var express = require("express");
var app = express();
var server = require('http').Server(app);

app.get('/', function (req, res) {
    res.sendFile(__dirname + '/web/index.html');
});
app.use('/web', express.static(__dirname + '/web'));
server.listen(2000); 

console.log('Started Server!');

by calling

node app.js

it does not show the alert when the HTML page loads. I just installed node.js and installed the node express dependencies in this app after I called "node init" on the project.



via Kevin Hu

No comments:

Post a Comment