導航:首頁 > 編程語言 > nodejs標准輸出

nodejs標准輸出

發布時間:2025-01-10 13:40:49

① 如何讓nodejslinux後台運行

加入 主文件是 index.js
那麼可以用的方法有:
1.用forever 進行管理版
npm install -g forever
forever start index.js

2. 用自帶的服務權nohub
nohup node index.js > myLog.log 2>&1 &

② 原生nodejs,res.end()無法輸出到頁面。

varhttp=require("http");varpath=require("path");varurl=require("url");varfs=require("fs");varejs=require("ejs");varserver=http.createServer(function(req,res){if(req.url=="/favicon.ico"){return;
}varpathname=url.parse(req.url).pathname;varfileUrl=path.normalize("./public/"+pathname);varextname=path.extname(pathname);

fs.readFile(fileUrl,function(err,fileData){
getMime(extname,function(mime){
res.writeHead(200,{"context-type":mime});
res.end(fileData);
})
});if(pathname=="/"){var_thisUrl="./public"
varfileArry=[];//存儲各個文件data的一些數據
vara={}vardata={};//存儲file(是否事文件,1是,0不是);fileName:文件(夾)名;url:文件實際地址
fs.readdir(_thisUrl,function(err,files){varlength=files.length;
(functioniterator(i){varshow=0;if(i>=files.length){
data={"fa":fileArry,"length":length};

fs.readFile("./views/index.ejs",function(err,fileData){vartemplate=fileData.toString();varhtml=ejs.render(template,data);console.log(html);
res.end(html);
});return;
}
fs.stat(_thisUrl+"/"+files[i],function(err,stats){if(stats.isDirectory()){
a={"file":0,"fileName":files[i],"url":_thisUrl+"/"+files[i]}
}else{if(path.extname("/"+files[i]).toLocaleLowerCase()==".jpg"){
show=1;
}
a={"file":1,"fileName":files[i],"url":_thisUrl+"/"+files[i],"show":show}
}
fileArry.push(a);//console.log(fileArry);
iterator(i+1);
})
})(0);

});

};});

server.listen(3000,"127.0.0.1");functiongetMime(extname,fn){
fs.readFile("./public/mime.json",function(err,data){varmimeList=JSON.parse(data);varmime=mimeList[extname];
fn(mime);
})
}

③ nodejs怎麼輸出文件的後綴名

閱讀全文

與nodejs標准輸出相關的資料

熱點內容
怎麼添加描述文件 瀏覽:890
路由固件開發工具 瀏覽:819
flash代碼checkbox顯示文字 瀏覽:226
java定義矩陣 瀏覽:609
如何創建word文檔 瀏覽:708
ug80模具設計全套教程 瀏覽:730
蘋果手機6p自帶壁紙 瀏覽:535
applestore評論不了 瀏覽:223
單韻母app哪個好 瀏覽:213
jstl和el習題 瀏覽:371
素描教學的網站有哪些 瀏覽:335
內存文件是干什麼的 瀏覽:725
win7共享登陸不用密碼怎麼設置 瀏覽:12
電腦分盤怎麼分app 瀏覽:476
手機安裝沒有應用程序怎麼辦 瀏覽:932
jsp按鈕關閉 瀏覽:63
資料庫的組織模型 瀏覽:852
怎麼用vi清空文件內容 瀏覽:953
為什麼我把文件重命名改了 瀏覽:52
菜單進行文件夾移動需要經過 瀏覽:72

友情鏈接