Using non-inline javascript in HTML via node.js -


i'm new node.js apologize if poor question. have simple http server here:

var http = require('http');  http.createserver(function (request, response){      response.writehead(200, {"content-type":"text/html"}); //  response.write("<html><head><script type = 'text/javascript'>alert('hello');</script></head></html>");     response.write("<html><head><script type = 'text/javascript' src = 'alerter.js'></script></head></html>");     response.end(); }).listen(8000);  console.log("server has started."); 

alerter.js contains 1 line:

alert("hello"); 

why using commented-out line cause alert, calling alerter.js nothing?

your problem, paul , timothy pointed out, when browser gets html external reference, goes server , asks alerter.js, expecting have script delivered it. however, server sends out same thing regardless of request asks for, browser never gets script.

you need change server to, @ least, handle request alerter.js. realistically, i'd use connect's static file handler that; put assets scripts, stylesheets , images in directory (usually called "public") , tell static handler serve them there.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -