NodeJS学习计划(1)

1、案例一

var fs = require("fs");
console.log("starting");

//读取文件中的内容
var content =fs.readFileSync("./Node.js.txt");
console.log("content"+content);
//监听文件中的内容是否有变化,如果改变 ,显示出新的内容
fs.watchFile("./config.json",function(current,previous){
    console.log("config changed");
    content= JSON.parse(fs.readFileSync("./config.json"));
    console.log(content);
});

2、案例二】

//监听网页的地址

var fs = require("fs");
var config =JSON.parse(fs.readFileSync("config.json"));

var host = config.host;
var port = config.port;

var express = require("express");
var app = express();
app.get("/" ,function(request,response){
    response.send("hello");
});

app.get("/:id" ,function(request,response){
    response.send("hello"+request.params.id);
});

app.listen(port,host);

 

 

 

 

posted @ 2014-02-25 11:39  风语9  阅读(214)  评论(0编辑  收藏  举报