iT邦幫忙

4

Express ( Nodejs ) 讀取檔案

要讀出檔案必須載入 require('fs') 使用 readFile
要讀出檔案必須載入 require('fs') 使用 readFile

var express = require('express');
var app = express.createServer();
var fs = require('fs');

app.get('/hello', function(req, res){
 fs.readFile('index.html', function(err,data){
  if(err) throw err;
  res.end(data.toString());
 });
});

app.listen(8080);
console.log('creat server success.');

當你瀏覽 http://localhost:8080/hello 時就會列出 index.html 的檔案內容了

如果有問題可以到我的blog提出 http://fire.bkbox.us/2012/04/express-nodejs.html


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言