node.js中restful

var express = require('express');
var app = express();
var fs = require("fs");
app.get('/listUsers', function (req, res) {
   fs.readFile( __dirname + "/" + "rest.json", 'utf8', function (err, data) {
       console.log( data );
       res.end( data );
   });
})
var server = app.listen(8081, function () {
  var host = server.address().address
  var port = server.address().port
  console.log("应用实例,访问地址为 http://%s:%s", host, port)

})

rest.json

{
   "user1" : {
      "name" : "mahesh",
 "password" : "password1",
 "profession" : "teacher",
 "id": 1
   },
   "user2" : {
      "name" : "suresh",
 "password" : "password2",
 "profession" : "librarian",
 "id": 2
   },
   "user3" : {
      "name" : "ramesh",
 "password" : "password3",
 "profession" : "clerk",
 "id": 3
   }
}

    A+
发布日期:2016年08月01日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: