Express Static nodejs [英] Express Static nodejs

查看:117
本文介绍了Express Static 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()块确保快递正常运行,但我仍然无法请求静态文件。

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






README

test







$ curl http://localhost:8080/README
test







$ npm ls
connect@1.6.1
express@2.4.4

这篇关于Express Static nodejs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆