Well, everything you already know with JavaScript can be played here, except for the DOM, which if you don't know, includes interacting with a website.
For example we can do some basic console.logs() in Node.js
const x = 6;
// Console commands work as normal
console.log('x is ' + 6); // Returns 'x is 6'
//But with ES5 you can do this:
console.log(`x is ${x}`); // Returns 'x is 6'
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
const variableToHoldContentOfModule = require('module name as it should be')
Can we import a module as an example?
Yeah ok, lets use the OS module
It can help with determining what module to use.
// Import the module, using require syntax
let os = require('os');
//now that we have the os module, we can use the docs to help us find out our platform. Do this by tacking on .platform() to it.
console.log(`Your platform is ${os.platform()}`)
//now on repl it will be weird to some, as it says Linux, but thats because repl uses a virtual machine built on linux.
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:
// Write some code that you want to share with index.js,
let x = 'some random text to export';
function add(x, y) {
return x + y; //simle add function
}
function sub(x, y) {
return x - y; //simle subtract function
}
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.
module.exports = {
addFunction: add,
subFunction: sub,
randomText: x
}
Come back to index.js and import it
//Node already knows its a js file so you dont need the extension
const moduleWeGot = require('./module');
// the "./" refers to the root directory
// Time to see our options:
console.log(moduleWeGot);
We see this:
{
addFunction: [Function: add],
subFunction: [Function: sub],
randomText: 'some random text to export'
}
Our data is there, so now we can just get them with some dot notation.
@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.
@RohilPatel The point of a tutorial is to explain how to do something. Nowhere in this tutorial does it explain anything about how to do server-side things.
Node.js Tutorial
What is the syntax like?
Well, everything you already know with JavaScript can be played here, except for the DOM, which if you don't know, includes interacting with a website.
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
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!!
ha modules is also node's downfall.
Yeah import is much better =/. Did u like the repl? @realTronsi
Or I mean the tutorial @realTronsi
@RohilPatel not much content but yeah decent tutorial
Yeah lol, upvote if u want. Is there anything you think I should make? I'm far more advanced than this tut @realTronsi
quick steps with functions, variables, loops, and if statements / switch statements. Maybe even JSON objects. @RohilPatel
@Theboys619 lol those are too beginner
i guess. @realTronsi
Yea a little beginner, I'll probably teach ejs and data passing @realTronsi
@RohilPatel hm lol ok
lolololololol @realTronsi
@RohilPatel I like to think I know a lot about node, but like what is ejs and data passing
@firefish ejs is just a rendering template, and I don't know what he means by data passing lol
@realTronsi I had a look at some ejs code, and pug looks more elegant than
<%=
stuff.@firefish I never really used pug, but the ejs tag allows you to do expressions and stuff, not sure if pugjs is the same
@realTronsi like what kind of expressions, but I'm not exactly an expert at pugjs, @Coder100 is however
pug js more like EJS @firefish
Ok C tutorial when @firefish
@Coder100 ejs more like using websockets to send variables over and then replacing the innerHTML with the variable smort
@Coder100 Why do you need C tutorial
Because C good @realTronsi
@Coder100 I thought you know C
@Coder100
C
? YES POG POGtrying to speak cookeylangPOG POG C TUTORIAL POG POG@firefish how much C do you know
@realTronsi moderate amount, here is most of my nkowledge concentrated into one repl: https://repl.it/@firefish/myMem
@firefish wait lol what is this for:
@realTronsi Index-out-of-range is not prohibited.
@firefish I know so why is that your function?
POG POG POG POOGG @firefish
that's why im writing it @realTronsi
@realTronsi random number generator
poogg? what in the world @Coder100
no but your random number generator is returning an invalid index, its going to seg fault no? @firefish
@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.
@firefish oh so it isn't random then though?
also thought this seg faulted but apparently this doesnt:
@firefish
interesting result
@realTronsi Well, the randomness occurs at compile-time, in the form of how to arrange the binary, rather than at runtime.
@realTronsi is
4195632
interesting at all?@firefish what? I don't see how pseudorandomness can occur from compiling?
@firefish not sure what it comes from, doesn't change from manipulating the list
@realTronsi Ah, just realised.

clang
does things differently than to gcc.@realTronsi I know, the
clang
version works as expected however thegcc
one does not@realTronsi @fuzzyastrocat Nightmare code: malloc bomb + fork bomb

@firefish what is that syntax highlighting ewww
@realTronsi my theme, thanks for reminding me that it is not normal syntax highlighting
@realTronsi HELP
@firefish ah yes perfection
@RohilPatel Please actually cover node's strength and main use case: writing server applications.
@fuzzyastrocat and also having simultaneously the worst and best package manager
Yep I did @fuzzyastrocat
Data passing is where you send something from the backend to the front end.
@realTronsi
oh, just cover templating engines instead then @RohilPatel
yeah probably. @realTronsi
@RohilPatel Uh, where? All I see in the tutorial is modules.
In the "ok, why NodeJs" @fuzzyastrocat
@RohilPatel The point of a tutorial is to explain how to do something. Nowhere in this tutorial does it explain anything about how to do server-side things.