DEV Community

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

Posted on

3

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

SurveyJS custom survey software

Simplify data collection in your JS app with a fully integrated form management platform. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more. Integrates with any backend system, giving you full control over your data and no user limits.

Learn more

Top comments (0)

Cloudinary image

Video API: manage, encode, and optimize for any device, channel or network condition. Deliver branded video experiences in minutes and get deep engagement insights.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay