如題
目前有兩種指令,一種為長指令
127.0.0.1:1337/FirstPassYield?filePath=D:\Project\SmartFactory\EXE
if(FilePath_ay[0]==="SmartFactoryFile")
{
var i1000JsonFile_A=FilePath_ay[1]+".json"; // i1000JsonFile_A = 檔名+副檔名
console.log("i1000JsonFile_A = "+i1000JsonFile_A);
RootPath_A=RootPath_A+FilePath_ay[1]+".json"; // 總路徑
var fs = require('fs')
fs.stat(RootPath_A, function(err, stat) //
{
if(stat&&stat.isFile())
{
fs.readFile(RootPath_A, function (err, data)
{
console.log(data.toString());
res.write(data);
});
}
else
{
console.log("400 Bad Request. The < "+i1000JsonFile_A+" > not found.");
res.write("400 Bad Request. The < "+i1000JsonFile_A+" > not found.");
}
----------------------------------------------------------------------------- 在readFile裡面只要沒有res.end();,就不會將顯示結果顯示於瀏覽器上,並且網頁也會無回應,但加了end又會與function抵觸,錯誤碼為
Error:write after end 請問我應該怎麼作,能讓找完檔案後的資料顯示於瀏覽器上,又不會有錯誤,請高手教導我,謝謝您