Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7680701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:10:32+00:00 2026-05-31T18:10:32+00:00

// Server.js var http = require(‘http’); var path = require(‘path’); var fs = require(‘fs’);

  • 0

// Server.js

var http = require('http');
var path = require('path');
var fs = require('fs');

http.createServer(function (request, response) {

    console.log('request starting...');

    var filePath = '.' + request.url;
    if (filePath == './')
        filePath = './index.html';

    path.exists(filePath, function(exists) {

        if (exists) {
            fs.readFile(filePath, function(error, content) {
                if (error) {
                    response.writeHead(500);
                    response.end();
                }
                else {
                    response.writeHead(200, { 'Content-Type': 'text/html' });
                    response.end(content, 'utf-8');
                }
            });
        }
        else {
            response.writeHead(404);
            response.end();
        }
    });

}).listen(8125);

console.log('Server running at http://127.0.0.1:8125/');

// index.html

<html>
    <head>
        <title>Rockin' Page</title>
        <link type="text/css" rel="stylesheet" href="style.css" />
        <script type="text/javascript" src="jquery-1.7.1.min.js"></script>   
        </head>
    <body>
        <p>This is a page. For realz, yo.</p>
    </body>
    <script type="text/javascript">
        $(document).ready(function() {
            alert('happenin');
        });
    </script>
</html>

I am able to run my static page, but i have couple of questions down the line.

  1. What do i do next? i mean what to develop and what to learn? i am confused.. what is the difference i am doing with my current webserver.
  2. Is node.js just an replacement of my Apache Webserver.
  3. Can anyone clearly explain me the main purpose of nodejs
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:10:33+00:00Added an answer on May 31, 2026 at 6:10 pm

    Questions

    1. What do i do next? i mean what to develop and what to learn? i am confused.. what is the difference i am doing with my current webserver.
    2. Is node.js just an replacement of my Apache Webserver.
    3. Can anyone clearly explain me the main purpose of nodejs

    Answers

    1. Start with some simple examples and/or tutorials. I’ve forked Mastering Node on github, which is a quick read but is also still a work in progress. I’ve used expressjs for quickly creating static sites (like my online resume). I also use node.js and nodeunit for testing JavaScript or performing scripting tasks that could otherwise be done in bash, php, batch, perl, etc.

    2. node.js gives an IO wrapper to Google’s V8 JavaScript engine. This means that JavaScript is not bound to a web browser and can interact with any type of IO. That means files, sockets, processes (phihag’s Turing-complete answer). It can do pretty much anything.

    3. The main purpose of nodejs is that IO code is evented and (mostly) non-blocking. For example, in ASP.NET, when a web server receives a request that request’s thread is blocked until all processing is complete (unless processed by an asynchronous handler, which is the exception not the rule). In node.js (express, railwayjs, etc.), the request processing is handled by events and callbacks. Code is executed asynchronously and callbacks are executed when complete. This is similar to the asynchronous pages of ASP.NET, the main difference being that node.js and web frameworks on top of it don’t create millions of threads. I believe the threading issue is discussed in Ryan’s video.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Checking the simple code var http = require('http'); var server = http.createServer(function(req, res){ console.log(Got
I have simple node js http server. var http = require(http); http.createServer(function(request, response) {
Consider the following example: var http = require('http'); var server = http.createServer(function(request, response) {
var http = require(http); function onRequest(request, response) { console.log(Request received.); response.writeHead(200, {Content-Type: text/plain}); response.write(Hello
Check the code var server = http.createServer(function(req, res){ var parsedUrl = require('url').parse(req.url); var pathname
My server.js seems to be correct.. var http = require('http'); http.createServer(function (req, res) {
I just grabbed that code from an online tutorial: var http = require('http'); http.createServer(function
I have a Hello.js file with following contents. var http = require('http'); http.createServer(function (req,
server code var http = require('http'), io = require('socket.io'), fs = require('fs'); respcont =
I have the following simple http server using Node.js: var http = require('http'); var

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.