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

1
  • Why don't you use some of nodejs frameworks like Express, hapi..etc Commented Oct 7, 2019 at 8:33

2 Answers 2

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>

Sign up to request clarification or add additional context in comments.

2 Comments

now i want practice only nodejs so is there any solution?
probably yes but is not that common, you can check some other solutions here: stackoverflow.com/questions/6084360/…
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

1 Comment

now i want a practice only node js is there any solution?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.