I’m trying to learn node, I saw lot of material (as suggested in that famous SO question), the problem is that all the books I saw, or tutorials either use a web framework like express or simply limit themselves to explain what node is and go no deeper than explaining how to create a very basic http server which listens for requests on some port.
So I’m really wondering is there anybody who uses node w/o a web framework? If so they must have learned it somewhere, so could you please suggest where can I learn it?
I know that this is very low level, but I don’t mind, I have already a familiarity on how to create servers in C.
I’d really like to understand how we really serve static content with node (customly organized in folders) and how we actually introduce logic into our html (I looked all this up but found only results on how to do it using Express, where logic is introduced by something like <% //code %>, but can this be done in pure node?).
The question similar to mine which has been already asked here does not really have an answer. The best answer just suggests to read the official nodejs documentation which is like saying:
there you have a dictionary with millions of words in Latin, good luck in learning it.
So can you suggest some well documented, robust book/ tutorial where is shown how to create a real world website using raw node?
If not, I guess I’ll have to stick to php + Apache and try to optimize those to scale.
So I guess “raw” node just means solving whatever problem you want to solve without building on top of 3rd party libraries (beyond the standard library that node.js comes with). Personally, I’m not sure why you really want to do that. One huge advantage of node.js development is the whole NPM eco-system where there are thousands of pre-built, free and open source modules that solve thousands of problems. Some are a few functions, but still useful and others are whole APIs that solve rich sets of problems. The beauty of NPM and this eco-system is that with one simple command you can add any one of these modules to your project and with a couple lines of code, you can be using it in your project. I’d consider it silly to avoid this advantage.
Unfortunately, the documentation for the node.js standard library is not richly descriptive (I’m being kind there). It’s technically accurate, but often doesn’t answer many of the common questions anyone wanting to use an API would quickly have. It appears to assume that you already know a lot of the Unix C standard library as it has many similar functions (particularly for file access). Plus, one of the documentation drawbacks of an object hierarchy (where things inherit from other things) is that it can be hard to put together in one place everything that a given object does. Instead you have to mentally collect and understand what the base objects do and then try to figure out how that fits in to what the root object is doing. This isn’t a challenge that only node.js faces, lots of object oriented systems have this documentation challenge (it used to drive me nuts with YUI).
What I quickly found is that I really needed to be able to find the relevant library source code for any standard library function so I could look at how the function was actually written in order to answer my questions. This is such a huge advantage of both open source and how searchable GitHub is (all the standard library source is on GitHub).
So, page through all the modules in the node.js standard library to familiarize yourself with what is there and where you’d find it. Then find yourself an app you want to build and build it. If you’re building a web app, I can think of no reason why you would ever want to do that without using a framework someone else has already built for you (I use Express). There’s just no reason to reinvent everything yourself. If you want to make sure you understand the HTTP module before using Express, then build yourself a simple web server using only the HTTP module that serves two static files and use the HTTP module going the other way to request a couple web pages from other servers. Then, start using Express to build your own web app.
As for some of your more specific questions:
I’d really like to understand how we really serve static content with
node (customly organized in folders)
how we actually introduce logic into our html (I looked all this up
but found only results on how to do it using Express, where logic is
introduced by something like <% //code %>, but can this be done in
Introducing “logic” into your HTML from scratch means that you first build a system for serving static web pages and then you add to that a system for parsing through the web pages (on the server) to find directives in them that mean your server should do something to modify or add to the HTML before sending it to the client. There are many different ways of doing this which is why there are probably 50 different systems out there already for doing this. A search for node.js template systems will find you a list. Again, I have no idea why you would want to build one of these from scratch. It is a bit of a research project to figure out which of the zillions out there matches your desires the best (I’m using Handlebars, a derivative of Mustache myself), but that should be way, way less work than building your own system from scratch. And, even if you want some grand capabilities that can’t be easily accomplished with a stock system, you may as well start with a stock system and extend it.
What you’re asking for seems to be two different things, you want to do raw Node, but at the same time know how people use it in the real world. Pretty much everyone uses at the very least, Express (or Koa if you’re on the bleeding edge) as their web framework. They provide the bare bones to create a robust web server. Then, for your actual front end, you’d use either AngularJS or ReactJS, you wouldn’t do any rendering server side template rendering (e.g. no <% %> code blocks). If you choose to go the React route, you’ll need additional libraries like BaconJS to assist with the glue, as React is just the view layer, whereas Angular is an all encompassing MVC framework.
One of the best ways to learn, is to look at the MEAN stack yeoman generator https://github.com/DaftMonk/generator-angular-fullstack . Use the generator to make an app, and read its source to see how it is structured, and just start hacking away at it to get to do what you want.