express4 中间件、读文件

const express = require('express')
app = express()


var fs = require('fs');
var contentText = fs.readFileSync('a.json','utf-8');


app.get('/',(req,res)=>res.send('hello'+contentText))
app.listen(10010,()=>console.log('listen in 10010'))
View Code

 

 

server

const express = require('express')
app = express()
app.use('/s',express.static('E://web'))
app.listen(10011,()=>console.log('listen in 10011'))

 

pack.json

{
  "name": "4",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.17.1"
  }
}
View Code

 

posted @ 2020-05-06 22:30  justSmile2  阅读(286)  评论(0)    收藏  举报