Express 静态 nodejs [英] Express Static nodejs
本文介绍了Express 静态 nodejs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public
中有一个 style.css
,但我似乎无法使快速静态选项起作用.我删除了 express
并完成了 npm install express
,但它仍然无法正常工作.我刚收到 404 错误.
There is a style.css
in public
, but I can't seem to make the express static option work. I deleted express
and have done npm install express
, but still it isn't working. I just get a 404 error.
var express = require('express')
, app = express.createServer();
app.use(express.static(__dirname+'/public'));
app.listen(8080, "127.0.0.1");
我添加了一个 app.get()
块以确保 express 正常运行,但我仍然无法请求静态文件.
I have added an app.get()
block to insure express is properly running, but I am still unable to request the static file.
推荐答案
对我来说效果很好.
app.js
var express = require('express')
, app = express.createServer();
app.use(express.static(__dirname+'/public'));
app.listen(8080, "127.0.0.1");
<小时>
mkdir public
cd public
touch README
<小时>
自述文件
test
<小时>
$ curl http://localhost:8080/README
test
<小时>
$ npm ls
connect@1.6.1
express@2.4.4
这篇关于Express 静态 nodejs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文