dis*_*290 4 javascript node.js
这是我的一个简单node.js应用程序的代码:
var http = require('http');
var fs = require('fs');
var path = require('path');
var url = require('url');
var port = process.env.port || 1337;
http.createServer(function onRequest(req, res) {
var urlParts = url.parse(req.url);
var doc = '/docs' + urlParts.pathname;
path.exists(doc, function fileExists(exists) {
if (exists) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
fs.createReadStream(doc).pipe(res);
} else {
res.writeHead(404);
res.end('Not Fouind\n');
}
});
}).listen(port);
Run Code Online (Sandbox Code Playgroud)
当我尝试运行它时,我收到一条错误,内容如下:
path.exists(doc, function fileExists(exists) {
^
TypeError:Undefined is not a function
Run Code Online (Sandbox Code Playgroud)
这是从教程中复制的,所以我不确定发生了什么.(PS:我正在使用Visual Studio)
| 归档时间: |
|
| 查看次数: |
3429 次 |
| 最近记录: |