nodeJS使用express搭建简单http服务

const express = require('express');
const fs = require('fs')
const app = express();
app.get('/favicon.ico', function (req, res) {
    res.status(200)
    return
})
app.get('/', function (req, res) {
    const body = null
    try {
        const body = fs.readFileSync(__dirname + '/index.html', 'utf-8')
        res.send(body)
    } catch (error) {
        res.send(404, '404,文件未找到')
    }
})
app.listen(3000)
Posted in JS

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注