1
var http = require("http");
var fs = require("fs");

var todo = http.createServer(function(req, res) {
  fs.readFile("./todo.html", function(err, data) {
    if (err) {
      console.log("no");
    } else {
      res.writeHead(200, { "Content-Type": "text/html" });
      res.end(data);
    }
  });
});
todo.listen(3000);

here is my nodejs code i dont know how to include css js file . i cant include only html file. i want include css js file beacause i want built web app by nodejs

이정수
  • 11
  • 2

2 Answers2

1

You can include your css in todo.html

<link rel="stylesheet" type="text/css" href="styles.css">

or for JavaScript

<script src="scripts.js"></script>

Hai Alaluf
  • 757
  • 7
  • 15
  • now i want practice only nodejs so is there any solution? – 이정수 Oct 07 '19 at 09:12
  • probably yes but is not that common, you can check some other solutions here: https://stackoverflow.com/questions/6084360/using-node-js-as-a-simple-web-server – Hai Alaluf Oct 07 '19 at 13:44
0

if you need to build a web application using nodejs it is recommended to using nodejs framework like express.js (https://expressjs.com/) which already have basic building blocks to up and running quick web apps. please refer express.js documentation for basic routing and serving static files to build a simple web application. these are some starting guides

Rajith Thennakoon
  • 3,975
  • 2
  • 14
  • 24