CNode

请教 fs.exists() 方法

Ttsregll发布于13 年前最后回复12 年前15 回复6994 浏览0 收藏

最近在看TJ大神的 node in action 实验了其中的socket实时聊天网页,启动后报404错误,也就是找不到index.htm页,不知道各位有没有遇到,自己对了一下写的路径,应该没什么错误,请教大家,读取文件的话路径应该怎样写?

查看回复

回复 (15)

B
brighthas#1·13 年前
__dirname + "/yourfile.txt"

签名: 交流群244728015 《Node.js 服务器框架开发实战》 http://url.cn/Pn07N3

T
tsregll#2·13 年前

这是代表根目录下的txt文件么?

B
brighthas#3·13 年前
引用 tsregll这是代表根目录下的txt文件么?

no, mean is current code path.


签名: 交流群244728015 《Node.js 服务器框架开发实战》 http://url.cn/Pn07N3

T
tsregll#4·13 年前
引用 tsregll这是代表根目录下的txt文件么?

@brighthas给个路径的实例呗,作者给的inde.htm的路径是“./public/index.htm”

T
tsregll#5·13 年前

能给个 __dirname

R
ringtail#6·13 年前
引用 tsregll这是代表根目录下的txt文件么?

@brighthas 兄弟,你这个太贵了...

B
brighthas#7·13 年前
引用 tsregll这是代表根目录下的txt文件么?

@ringtail lol , many people buy, before the end of price increases.


签名: 交流群244728015 《Node.js 服务器框架开发实战》 http://url.cn/Pn07N3

T
tomgor#9·13 年前

__dirname? is working directory or source file directory?

M
mq1980#10·12 年前

__dirname 项目路径 ./ 当前路径

T
tsregll#11·13 年前
引用 tsregll这是代表根目录下的txt文件么?

@brighthas__dirname是什么?给一个实例吧。如:"./publc" 其中"./"代表什么什么

B
brighthas#12·13 年前
引用 tsregll这是代表根目录下的txt文件么?

@tsregll

This is the basic knowledge you need to educate yourself.


签名: 交流群244728015 《Node.js 服务器框架开发实战》 http://url.cn/Pn07N3

T
tsregll#13·13 年前
引用 tsregll这是代表根目录下的txt文件么?

@brighthas Well Ok I'll continue to read node in action ,thank you so much

Y
yaochun#14·12 年前
引用 tomgordirname? is working directory or source file directory?

是应该补补基础知识了,全局对象啊。。。

Z
zengwenbing#15·12 年前

module.exports = function () { console.log('启动的目录:' + process.cwd()); console.log('工作的目录:' + __dirname); }

参与回复
登录后即可参与回复。登录