簡體   English   中英

從Node.js讀取CSS文件

[英]Reading css file from nodejs

如何獲取節點js讀取的CSS文件。 我有下面的代碼讀取的html文件。

function displayForm(res) {
fs.readFile('index.html', function (err, data) {
    res.writeHead(200, {
        'Content-Type': 'text/html',
    });
    res.write(data);
    res.end();
});
 }

用同樣的方法

html

fs.readFile(__dirname + '/public/index.html', function (err, data) {
  if (err) console.log(err);
  res.writeHead(200, {'Content-Type': 'text/html'});
  res.write(data);
  res.end();
});

js

fs.readFile(__dirname + '/public/js/script.js', function (err, data) {
  if (err) console.log(err);
  res.writeHead(200, {'Content-Type': 'text/javascript'});
  res.write(data);
  res.end();
});

的CSS

fs.readFile(__dirname + '/public/css/style.css', function (err, data) {
  if (err) console.log(err);
  res.writeHead(200, {'Content-Type': 'text/css'});
  res.write(data);
  res.end();
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM