未定义不是一个函数:节点错误

每当我试图运行static.js,命令:

node static.js 

我收到错误:

  libpath.exists(filename, function (exists) { TypeError: undefined is not a function 

这是我的代码捕捉static.js:

 http.createServer(function (request, response) { var uri = url.parse(request.url).pathname; var filename = libpath.join(path, uri); libpath.exists(filename, function (exists) { if (!exists) { response.writeHead(404, { "Content-Type": "text/plain" }); response.write("404 Not Found\n"); response.end(); return; } 

我在开始时定义了libpath

 var libpath = require('path') 

存在函数没有在path模块中定义,它被定义为文件系统('fs')模块的一部分:

 var fs = require('fs'); fs.exists(filename, function (exists) { });