//静态资源管理器
//path ---join
var express=require('express');
var path=require('path');
//初始化一个入口函数
var app=express();
//express.static():搭建静态资源管理器(静态资源服务器)
console.log(path.join(__dirname));//文件目录
console.log(path.join(__filename));//文件名
app.listen(3000,function(){
console.log('正在进行中。。。。。')
})
express框架引入页面图片
//加载express 框架
var express=require('express');
var fs=require('fs');
//初始化入口函数
var app=express();
//中间件
app.get('/',function(req,res){
res.send('<img src="/img/cat.jpg">')
// res.end('hello World')
res.end();
})
app.use('/img/cat.jpg',function(req,res){
fs.readFile('./img/cat.jpg',function (err,data) {
if(err){
throw err
}
res.end(data)
})
})
app.get('/index',function(req,res){
fs.readFile('./public/index.html',function (err,data) {
if(err){
throw err
}
res.end(data)
})
})
app.use('/name',function(req,res){
// fs.readFile('./public/sec.html',function (err,data) {
// if(err){
// throw err
// }
// res.end(data)
// })
// res.send('name');
// res.end();
fs.readFile('./public/sec.html',function (err,data) {
if(err){
throw err
}
res.end(data)
})
})
app.listen(3070,function(){
console.log('程序正在执行')
})