sendFile issue

27 views
Skip to first unread message

Kim Pham

unread,
Aug 22, 2014, 12:22:20 PM8/22/14
to nod...@googlegroups.com
Hi All,
I want to render the page with the tenants.html but couldn't make it works. My web structure is:
            public
                   html
                   images
                   js
                  css
   
            routes
            views
Attached is my apps.js and tenants.html
Any thought why it didn't send the html file to browser.
Thanks,
J
app.js
tenants.html

Ryan Schmidt

unread,
Aug 23, 2014, 12:19:44 PM8/23/14
to nod...@googlegroups.com
Your app.js file contains mostly extraneous unused code related to the express framework. And then you completely ignore that and create your own server; the following appears to be the only code you're actually using:


var http = require('http'); //add the http module
var myServer = http.createServer(function(res, res) {
// res.writeHead(200, {"Content-Type" : "text/html"});
// res.write("<b>Hello</b> World");
// res.sendFile(html/tenants.html);
res.sendfile(__dirname + '/html/tenants.html');
res.end();
}); //create a server

myServer.listen(3000);


One problem I see is that the signature of the function you're passing to http.createServer is wrong: you've specified the argument name "res" twice. The first parameter should be "req" (for "request"), and the second parameter should be "res" (for "response"):


var myServer = http.createServer(function(req, res) {


Reply all
Reply to author
Forward
0 new messages