Irfan Irfan - 1 year ago 85
Node.js Question

Start nodejs in browser form begining?

I am new in Nodejs and using Mac OS (MAMP, localhost:8888), I have already installed and I can execute programs in terminal. But how to in build with html. Can, we include nodejs as a external library like (jQuery, Bootstrap).

Answer Source

Please refer this Hello world example. node.js

var http = require("http");
var server = http.createServer(handler);

var fs = require('fs');


function handler(req,resp){

            console.log("error in  loading file.");
            resp.end("failed to load")


    Hello world.!!

Once you mentioned port number in listen function,
node server will run on that port.
So until you are not giving same port number as Apache,you can run both Apache and nodejs parallel.
If your Apache and nodejs server sharing same port number , then you need to stop one of them in order to use other.

Your Question :

Can, we include nodejs as a external library like (jQuery, Bootstrap).

Node.js is not library.So you can not include it like jQuery or bootstrap.
It is platform for javascript to run on server side.
And using nodejs we can create Server which serve your content of Web like Apache do.

When you say node app.js (insead of app.js it can be any name) from your command prompt,you starting your node server.

In above example index.html you can include your jQuery or angular or bootstrap library as you do when using Apache

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download