成都网站设计的公司,医院网站和公众号建设方案,wordpress 翻页没内容,免费做一个自己app我需要借助node.js来获取文件的文件类型以设置内容类型。我知道我可以很容易地检查文件扩展名#xff0c;但我也有没有扩展名的文件#xff0c;其内容类型应该是image/png,text/html aso。Node.js - 文件系统获取文件类型这是我的代码(我知道这并没有太大的意义#xff0c;但…我需要借助node.js来获取文件的文件类型以设置内容类型。我知道我可以很容易地检查文件扩展名但我也有没有扩展名的文件其内容类型应该是image/png,text/html aso。Node.js - 文件系统获取文件类型这是我的代码(我知道这并没有太大的意义但是这就是我需要的基础)var http require(http),fs require(fs);http.createServer(function(req, res) {var data ;try {/** Do not use this code!* Its not async and it has a security issue.* The code style is also bad.*/data fs.readFileSync(/home/path/to/folder req.url);var type ???; // how to get the file type??res.writeHead(200, {Content-Type: type});} catch(e) {data 404 Not Found;res.writeHead(404, {Content-Type: text/plain});}res.write(data);res.end();}).listen(7000);我还没有找到一个函数该函数在API所以我会很高兴如果有人能告诉我该怎么做。2012-05-03noob6readFileSync on每个请求听起来不是一个好主意...... –3ThiefMaster正如他所说这只是虚拟代码(至少这就是我认为的“我知道这并没有多大的意义但这是我需要的基础”意思是)。 –