DEV Community

Cover image for Creating an HTML File Using Node.js A Step-by-Step guide.
Sudhanshu Gaikwad
Sudhanshu Gaikwad

Posted on

Creating an HTML File Using Node.js A Step-by-Step guide.

First you need to create a Folder. That folder opens in the vs code and installs some packages. Some commands are available below.

*Commands *
1) npm init
2) npm install nodemon

Create file index.js After that looks like this:
Image description

index.js

var htttp = require("http");
var fs = require("fs");
var port = 1010;
var val = htttp.createServer(function (req, res) {
  fs.writeFile("testing.html", "This is 2021 ", function (err) {
    if (err) throw err;
    res.write("Your file Created..!");
    res.end();
  });
});

val.listen(port, () => {
  console.log("Server Started on ", port);
});

Enter fullscreen mode Exit fullscreen mode

Then Start the server, Go to the command prompt and Type Command.

npx nodemon index.js

Image description

Your server will start, and your testing.html created in the folder looks like this.

Image description

testing.html

Image description

Top comments (0)