Provide an HTML page with JS with node.js and express -
i trying serve html page linked js script using node.js , express. server provide page:
var express = require("express"); var app2 = express(); app2.get('/', function(req, res) { res.sendfile('./index.html'); }); app2.listen(process.env.vcap_app_port || 3000);
and page:
<!doctype html> <html> <head> <title>demo</title> </head> <body> <h1>demo</h1> <script src="/js/socket.io.js"></script> <script src="/js/codice.js"></script> </body>
as can see have 2 js scripts in js folder not loaded when launch page. can do?
what place public resources (javascript files, css files, images etc) in directory (express names public default) , utilize express.static
middleware in app.configure
call:
app.configure(function () { // various other middleware functions... app.use(express.static(path.join(__dirname, "public"))); });
this runs static file server homecoming file within public directory. currently, browser making request js files, express server doesn't know them. time out.
if generate initial state of app global express
executable (available if installed express via npm globally), set of you.
node.js express
No comments:
Post a Comment