server.js
const express = require('express'); //express框架模块
const path = require('path'); //系统路径模块
const app = express();
const hostName = '127.0.0.1'; //ip
const port = 8080; //端口
app.use(express.static(path.join(__dirname, 'public'))); //指定静态文件目录
app.listen(port, hostName, function() {
console.log(`服务器运行在http://${hostName}:${port}`);
});
文件目录结构
test/
├── server.js
│
├── public/
│ ├── index.html
│ │
│ ├── css/
│ │ └── style.css
│ │
│ └── js/
│ └── index.js
│
└── node_modules/
├── ...
├── ...
└── ...
访问方式
http://127.0.0.1:8080/index.html
http://127.0.0.1:8080/css/index.css
http://127.0.0.1:8080/js/index.js
1591

被折叠的 条评论
为什么被折叠?



