var express = require('express'); var app = express(); app.use(express.static('public')); app.listen(80, function () { console.log('Example app listening on port 80!'); });
在index.html中获取如下:
1 2 3
$.getJSON('conf/demo.json', function (data) { console.log(data); })
2.服务端 index.js内容如下:
1 2 3 4 5 6 7 8 9
var express = require('express'); var app = express(); var CONFPATH = "./public/conf/demo.json"; var fs = require('fs'); var result = JSON.parse(fs.readFileSync(CONFPATH)); console.log(result); app.listen(80, function () { console.log('Example app listening on port 80!'); });