Php Node.js可以';无法获取css文件

Php Node.js可以';无法获取css文件,php,html,css,node.js,Php,Html,Css,Node.js,我想通过Node.js localhost获取css文件index.php加载正确,style.css无法加载 我的结构文件 app.js views index.php css style.css 我的app.js const http = require('http'); const fs = require('fs'); const hostname = '127.0.0.1'; const port = 3000; fs.readFile('vi

我想通过Node.js localhost获取css文件index.php加载正确,style.css无法加载

我的结构文件

app.js views
     index.php
     css
        style.css
我的app.js

const http = require('http');
const fs = require('fs');

const hostname = '127.0.0.1';
const port = 3000;

fs.readFile('views/index.php', (err, html) => {
    if (err) {
        throw err;
    }

    const server = http.createServer((req, res) => {
        res.statusCode = 200;
        res.setHeader('Content-type', 'text/html');
        res.write(html);
        res.end();
    });

    server.listen(port, hostname, () => {
        console.log('Server started on port ' + port + (Date.now()));
        console.log('address ' + hostname);
    });
});
my index.php

<html>
    <head>
        <link rel="stylesheet" href="css/style.css" />
        <title>title</title>
    </head>
</html>

标题

<代码> > p>如果你想使用PHP,也许你应该考虑服务器以外的其他东西。还有像MAMP等软件包。css没有加载的原因是你只有一种到达服务器的方式,这会呈现你的索引文件。

你的服务器在每次响应时都会将html文件提供给客户端,这就是你的样式无法加载的原因。