JavaScript - Render HTML With Bootstrap Using Node.js

In this tutorial we will create a Render HTML With Bootstrap Using Node.js. The Node.js is a run-time environment includes everything you need to execute a program written in JavaScript. It is an open source, cross-platform runtime environment for developing server-side and networking applications. It is widely use by developers because it provide multiple libraries that simplifies the web development.

Getting started

After Node.js is installed, open the command prompt then type "npm install -g nodemon", and hit enter.
This will install nodemon, a tool that helps develop node.js based applications by automatically restarting the node application when file changes in the directory are detected.

The Main Interface

This code contains the interface of the application. This code will render application and display the form. First cd to your working directory and write these block of code inside the text editor and save this as index.html.

Creating the Script

This code contains the main function of the application. This code will create a server side script that let you access your website locally. To that just kindly copy and write these block of codes inside the text editor, then save it to your working directory as server.js.

var http = require('http');

var fs = require('fs');

var url = require('url');

var path = require('path');

var server = http.createServer(function(request, response){

var pathname = url.parse(request.url).pathname;

var ext = path.extname(pathname);

if(ext){

if(ext !='.ico'){

if(ext ==='.css'){

response.writeHead(200,{"Content-Type":"text/css"});

}elseif(ext ==='.js'){

response.writeHead(200,{"Content-Type":"text/js"});

}

response.write(fs.readFileSync(__dirname + pathname,'utf8'));

}

}else{

response.writeHead(200,{"Content-Type":"text/html"});

response.write(fs.readFileSync("index.html","utf8"));

}

response.end();

}).listen(8080)

There you have it we successfully created a Render HTML With Bootstrap Using Node.js. I hope that this very simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!!

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.