• We just launched and are currently in beta. Join us as we build and grow the community.

JavaScript - Render HTML With Bootstrap Using Node.js

santis1

Patch Analyst
S Rep
0
0
0
Rep
0
S Vouches
0
0
0
Vouches
0
Posts
167
Likes
39
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 100 XP
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

First you will need to download & install the Node.js, here's the link https://nodejs.org/en/.

After Node.js is installed, open the command prompt then type "npm install -g nodemon", and hit enter.
2019-01-03_20_17_40-c_windows_system32_cmd.exe_.png

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.
  1. <!DOCTYPE html>
  2. <html

    lang

    =

    "en"

    >
  3. <head

    >
  4. <title

    >

    Sourcecodester</

    title

    >
  5. <link

    type

    =

    'text/css'

    href

    =

    'css/bootstrap.css'

    rel

    =

    'stylesheet'

    /

    >
  6. </

    head

    >
  7. <body

    >
  8. <nav class

    =

    "navbar navbar-default"

    >
  9. <div

    class

    =

    "container-fluid"

    >
  10. <a

    class

    =

    "navbar-brand"

    href

    =

    "https://sourcecodester.com"

    >

    Sourcecodester</

    a

    >
  11. </

    div

    >
  12. </

    nav>
  13. <div

    class

    =

    "col-md-3"

    ></

    div

    >
  14. <div

    class

    =

    "col-md-6 well"

    >
  15. <h3

    class

    =

    "text-primary"

    >

    JavaScript - Render HTML With Bootstrap Using Node.js</

    h3

    >
  16. <hr

    style

    =

    "border-top:1px dotted #ccc;"

    /

    >
  17. <center

    ><h2

    >

    Bootstrap has started</

    h2

    ></

    center

    >
  18. <center

    ><button

    type

    =

    "button"

    class

    =

    "btn btn-primary btn-lg"

    data-target

    =

    "#form_modal"

    data-toggle=

    "modal"

    >

    Modal</

    button

    ></

    center

    >
  19. </

    div

    >
  20. <div

    class

    =

    "modal fade"

    id

    =

    "form_modal"

    aria-hidden=

    "true"

    >
  21. <div

    class

    =

    "modal-dialog"

    >
  22. <div

    class

    =

    "modal-content"

    >
  23. <div

    class

    =

    "modal-header"

    >
  24. <h3

    class

    =

    "modal-title"

    >

    System</

    h3

    >
  25. </

    div

    >
  26. <div

    class

    =

    "modal-body"

    >
  27. <center

    ><h2

    >

    Welcome to Node.js</

    h2

    ></

    center

    >
  28. </

    div

    >
  29. <div

    class

    =

    "modal-footer"

    >
  30. <button

    class

    =

    "btn btn-success"

    data-dismiss=

    "modal"

    >

    Close</

    button

    >
  31. </

    div

    >
  32. </

    div

    >
  33. </

    div

    >
  34. </

    div

    >
  35. <script

    src

    =

    "js/jquery-3.2.1.min.js"

    ></

    script

    >
  36. <script

    src

    =

    "js/bootstrap.js"

    ></

    script

    >
  37. </

    body

    >
  38. </

    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.
  1. var

    http =

    require(

    'http'

    )

    ;
  2. var

    fs =

    require(

    'fs'

    )

    ;
  3. var

    url =

    require(

    'url'

    )

    ;
  4. var

    path =

    require(

    'path'

    )

    ;
  5. var

    server =

    http.createServer

    (

    function

    (

    request,

    response)

    {
  6. var

    pathname =

    url.parse

    (

    request.url

    )

    .pathname

    ;
  7. var

    ext =

    path.extname

    (

    pathname)

    ;
  8. if

    (

    ext)

    {
  9. if

    (

    ext !=

    '.ico'

    )

    {
  10. if

    (

    ext ===

    '.css'

    )

    {
  11. response.writeHead

    (

    200

    ,

    {

    "Content-Type"

    :

    "text/css"

    }

    )

    ;
  12. }

    else

    if

    (

    ext ===

    '.js'

    )

    {
  13. response.writeHead

    (

    200

    ,

    {

    "Content-Type"

    :

    "text/js"

    }

    )

    ;
  14. }
  15. response.write

    (

    fs.readFileSync

    (

    __dirname +

    pathname,

    'utf8'

    )

    )

    ;
  16. }

  17. }

    else

    {
  18. response.writeHead

    (

    200

    ,

    {

    "Content-Type"

    :

    "text/html"

    }

    )

    ;

  19. response.write

    (

    fs.readFileSync

    (

    "index.html"

    ,

    "utf8"

    )

    )

    ;
  20. }

  21. response.end

    (

    )

    ;

  22. }

    )

    .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.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.

2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.


Download
You must upgrade your account or reply in the thread to view the hidden content.
 

452,496

337,656

337,664

Top