Learn Node.js in less than an hour [Tutorial]
What is the syntax like?
For example we can do some basic console.logs() in Node.js
Ok, but why Node.js
Well, first off, if you want to know why not to use python, I won't say anything, but if you are here because you don't know the difference between the browser js, then continue on.
Node.js makes everything come together. It's a server, which basically controls a bunch of people. Chat rooms send a message to the server, which sends it to everyone else.
Sign in pages send your typed data and check a database to see if it exists.
But it all starts here...
Node.js has something called a module
4 concepts to remember about modules
- A module must be imported
- Modules make Node.js work not like browser js
- Modules can make coding cleaner, resulting in more files and folders
- You can make a module very easily
Ok, how do you import a module
Well lets use the old fashion way because repl needs to update to node 14 for other things.
Below is how you import a module
Can we import a module as an example?
Yeah ok, lets use the OS module
It can help with determining what module to use.
How do we make our own module?
Well modules are just js files that work with the server. Try going into module.js at this time, or making it if you are following by yourself.
In there, we added the following code:
As of right now these functions and variables are local to the file, so to make them public, you do the following after everything was declared. It is usually the last thing in a file.
Come back to index.js and import it
// Time to see our options:
We see this:
Our data is there, so now we can just get them with some dot notation.
There is an easier way to get the module though
Then use the function as follows
I really hope this tutorial helps!!
Well, this isn’t really a NodeJS tutorial, you don’t go over anything that NodeJS is actually used for (Web Dev, App Launch, etc.) but instead just modules..
Congratulations! This tutorial now has more upvotes than the React tutorial! 😂
@realTronsi Aha, you see. It doesn't segfault because the index is only two places away from the end of the array, so there is stuff in accessible memory there. A SegFault occurs when you attempt to access memory that is inaccessible to your process, but the memory I am accessing is so close to the end of the array that it's probably reading the string passed to a printf call or something.