Node.js
What is it?
Node.js is a program that people use to make web apps. Since the way it is used is mostly for the internet, there isn't much you can do without the internet. It uses Javascript, the web language for modifying webpages.
What can you use it for?
Node can be used to make a program that can read your Instagram feed or do make how this slide document works. It is more or less, used for making web servers.
Functions
Functions are basically a way of making sure the program can multitask. For example, it allows asynchronous tasking, making it so that many people can connect to a website at the same time.
Modules are a way of sharing data to other scripts. When you want to send data to the main script in your program, you would use
module.exports = {
sayHello: function(){ return "Hello"; }
sayGoodbye: function(){ return "Goodbye.";}
}
Modules
fs.readFile('input.txt', function (err, data) { if (err) return console.error(err); console.log(data.toString()); }); the bolded text is a function.
Variables
Variables are for storing data for later use. It is also used to access downloaded modules. You can store strings of text, or a function from another file with module.exports.
var lel = "Vikstar123"
var sio = require('socket.io')
Events
Events are used like functions. They wait for something to happen like a webpage sending data to the server. I made an example that will be shown later.
socket.on('addpepl', function (data) {
fs.appendFile(pblc + '\\ppl.txt', data + "<br>", (err) => {
if (err) throw err;
console.log(data + "has been added to "+pblc+"\\ppl.txt");
});
}); //Event is in bold
NPM stands for Node Package Manager. It is a database for every packages you can download. It is a little complicated, but if you use NPM, you don't have to worry about having to downloading all of the files manually.
npm init
npm install -save express socket.io
Packages are third party modules downloaded and installed to make writing a program easier. When people have already made something, others use it, don't they?
Packages
Express is a package that is used for making web servers of any size. It uses functions to do different things like sending a file, or doing some sort of job before sending the page.
Socket.io is also a package but it is used to send and receive data from a webpage on a browser in real time instead of with the webpage. An application of this would be to have a chat webpage running and Socket.io would receive a message from a client and broadcast it to all of them.
Node.js
By Austin Taylor
Node.js
- 280