skip to Main Content

The last couple of days I began to teach myself how to create a Website from scratch.

I bought a webspace and fooled around with html, css and javascript and when I wanted to build a online chess game I learned about Node.js

But I don’t understand what Node.js is used for because the documentation shows how to install and create a fresh server(!) with Node.js and handle requests.

  • Do I don’t have to use a apache installation on my server anymore?

  • Do I create the whole website and all it’s pages with Node.js like the index or about page?

  • If I use Node.js just for a web application, how can I add the web app to an already existing Apache website’s page?

I think I really got confused and need some help to understand Node.js better since so many are using it.

2

Answers


  1. Do I don’t have to use a apache installation on my server anymore?

    Correct. You create your whole web server in node.js. You generally don’t use or need Apache with it.

    Do I create the whole website and all it’s pages with Node.js like the index or about page?

    Yes, you create the whole web server in node.js and use it to serve all your web pages. Typically one might use a number of libraries with node.js such as Express for mapping all the routes in your web app and your favorite template engine to help with filling in data in HTML pages before serving them to the client. At very high scale, one might consider using some other infrastructure (like nginx) to offload static resources from your node.js server to increase scalability, but that is not necessary at small or medium scale as node.js scales really well.

    If I use Node.js just for a web application, how can I add the web app to an already existing Apache website’s page?

    You can run one of the two web servers on a different port and have two web servers that are part of your web-site liking to each as needed. But, typically you would move everything you currently have in Apache over to your node.js app. You don’t have to do that, but most people wouldn’t start out with an objective to build a web-site out of both node.js and Apache.


    One thing to keep in mind is that node.js/Express are conceptually a bit different from Apache in how you build a simple web-site. A node.js/Express web server serves NO content at all by default. So, you don’t just drop a directory hierarchy of web pages on your node.js server and expect it to serve those pages by default. You can do that pretty easily with express.static() (a feature of the Express library) if that’s part of your site design, but you have to consciously configure that in node.js (it takes just two lines of code to do so).

    Login or Signup to reply.
  2. If you want to write a “simple” chess game, you’re best bet is to start learning Canvas. This tutorial by the Mozilla Foundation is one I personally used and enjoyed a lot. If you want the computer to play as CPU opponent, then you would likely need to use a server(node.js!).

    You can use Node.js to build a simple website, but that would be like using a screwdriver as a hammer. Node.js is used for making desktop apps and for programming servers. Servers(backend) analyze user inputs and provide some sort of feedback. Let’s use StackOverflow as an example. The frontend(HTML, CSS, Javascript) is what you see. All of that is done in the browser. The way you get that code to someone’s computer so they can render your website is via a server. Servers do other cool things. When you do a search on a website or save a post, the server is dealing with storing that data or finding you the right results. If you want to build an API, like the one used for Google maps, or for Yahoo Finance, you’d use a server.

    If you want to make your own server using Node.js, I’d recommend using Digital Ocean or Heroku. They are beginner-friendly and are respected in the industry. Heroku is free and owned by Salesforce if that makes a difference. However, this is unnecessary, for beginners. I recommend using a free or low-cost hosting platform that deals with that for you.

    The thing about Node.js is you can use it to create websites via template engines, but I wouldn’t recommend that. You are essentially writing server-side javascript to create HTML. That’s foolish most of the time when you can just write the HTML itself. Just have node.js deploy it.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search