I'm new in node.js, I have learn node.js and express framework
I know how to run server, set router and render html template basicly, but all the tutorial tell render the html by res.send()
or render
how can I view static file?Like static sample.html:
just like http://127.0.0.1:8000/static.html
my file tree like:
root
|
|---server.js
|---static
|---static.html
How can I view the static file by setting router?Or use some middleware(Better use express framework)?
Updated: I have try this:
var express = require('express');
var app = express.createServer();
app.get('/', function(req, res){
res.send('Hello World');
});
app.configure(function () {
app.use(express.static(__dirname + '/static'));
})
app.listen(8000);
but it still can not work: tell me:Cannot GET /static/client.html
Is your file named client.html
as specified in your update or is it named static.html
as you show in your file tree?
So, try either:
http://localhost:8000/client.html
or...
http://localhost:8000/static.html
Notice the lack of "/static" directory.
Also, put your app.configure
line before your app.get
.