Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

NodeJs Express setting a View to see folder's content rendered as html

NodeJs Express setting a View to see folder's content rendered as html

Problem

Having this code in my server.js

...
var express = require("express");
var app = express();

// Set the view directory to /views
app.set("views", __dirname);

http.createServer(app).listen(9001);
...

I'm excepting by going here ":9001/myhtml.html" to see my content. But instead I see:

Cannot GET /myhtml.html

Have I missed something?

Problem courtesy of: ses

Solution

app.use(express.static(path.join(__dirname, "/static_dir")))

See http://expressjs.com/faq.html

Solution courtesy of: Rell

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

NodeJs Express setting a View to see folder's content rendered as html

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×