The Rise of Machines: Real World Applications of AI
Kunstig intelligens er ikke i fremtiden, det er her lige i nuet I denne blog Læs, hvordan kunstig intelligens-applikationer har påvirket forskellige sektorer.
Node.js is both open source and free, and is used for a variety of purposes. To name a few, Node.js is very efficient for serving dynamic content. If you want a quick and efficient way to get a blog up and running, Node.js can simplify the process. Based on JavaScript, Node.js can be used by most web developers who wish to perform server-side operations without having to learn a completely new language. Node.js is also very memory efficient, handles all requests asynchronously, and the included package manager has access to the largest repository in the world.
Node.js has several advantages, such as the following:
npm.Unfortunately, though, Node.js does have it's share of disadvantages:
Update your package manager:
yum update -y
Install Node.js:
yum install nodejs -y
If you are prompted to import a key, enter Y to continue.
Ensure the installation was successful:
node -v
npm -v
All Node.js files must end with .js. For example, a simple quadratic solver can be called Quadratic.js. Having said that, you can call it whatever you'd like as long as the first requirement is met.
Programming languages usually have an API available, and Node.js is no exception. If you are lost or need to find the syntax for a function (or method), check out the Node.js docs.
NOTE: As mentioned previously, Node.js has a code-base that is updated constantly and as such, functions here may no longer work in later versions.
In this section, we'll be learning about the most basic program you can create. To begin, head to /~ or /root. Creating your first project is as simple as creating a JS file:
nano HelloWorld.js
Once you are inside your favourite text editor, enter the following:
// For reference, comments are made using '//' added before or after a line. Comments are ignored by the Node.js interpreter.
console.log("Hello, world!"); // console.log() simply outputs text to the terminal.
Exit and save.
Now, launch your program:
node HelloWorld.js
You will see the following output:
[root@test-server ~]# node HelloWorld.js
Hello, world!
In this section, we'll be learning how to perform basic mathematical operations. To begin, head to your /root directory again and create a file called MathTest.js:
nano MathTest.js
Paste the following code into the file:
var a = 5; // Variables are declared using 'var variableName = value'. The value can be a string, integer, boolean value (ie. true/false) or an object.
var b = 10;
var c = "Hello, world!";
console.log(c); // This line will output the contents of variable c.
console.log("a = " + a + ", b = " + b); // This line prints out the respective values for a & b.
console.log("a + b = " + (a + b)); // This line prints out the result of (a + b) or (5 + 10). The result should be 15.
Save and exit.
When you execute your MathTest.js program, you will see the following:
[root@test-server ~]# node MathTest.js
Hello, world!
a = 5, b = 10
a + b = 15
In this section, we'll be learning how to start up a Node.js webserver. To begin, create a file called WebTest.js:
nano WebTest.js
Paste the following code:
// This line includes the HTTP module. Having it included allows us to use it's methods and functions to start a working webserver.
var http = require("http");
var a = 5, b = 10;
http.createServer(function (request, response) {
// This will simply output "Request received!" to your terminal when you visit your page.
console.log("Request received!");
// This line tells your browser that it should be expecting HTML content to be returned.
response.writeHead(200, {'Content-Type': 'text/html'});
// The following line adds "Hello, world! a + b = 15" to the body. The <i></i> tags will italicize the text.
response.write("<i>Hello, world! a + b = " + (a + b) + "</i>");
// Finally, we'll tell the browser that we're done sending data with 'response.end()' below.
response.end();
}).listen(8080);
Once you've saved the file, run your new program:
[root@test-server ~]# node WebTest.js
Now, visit http://(YOUR_SERVER_IP):8080. Make sure to have your firewall configured correctly to allow the request.
You will see Request received! on your terminal and the following in your browser:
Hello, world! a + b = 15
NOTE: In order to close (shut down) WebTest.js, use the following key combination: CTRL + C.
Now that you understand some of the basics, the following section will introduce you to using 3rd party modules, installed via npm.
In this section, we'll be extending our first "Hello, world!" program. To begin, we'll be installing a package called colo. This package allows us to use colours on the terminal.
To begin, we'll be using npm to install the package:
npm i colo
For reference, you can remove the package with npm remove colo
Once the process completes, you will have access to the colo package. Now, once you've opened HelloWorld.js up, add the following line at the top:
var colour = require("colo");
Where you see console.log(...), encapsulate "Hello, world!" with brackets. At the start of the brackets, add colour.red.bold:
console.log(colour.red.bold("Hello, world!"));
Your final code will look like the following:
var colour = require("colo");
console.log(colour.red.bold("Hello, world!"));
Save, exit and run your program. The output will be exactly the same as before, except "Hello, world!" will now be red (and bold) in your terminal.
Congratulations on completing all the basic programs. This should provide you with the knowledge to interpret (at least most) of the code used in other tutorials. Hopefully, you don't stop here — there are many other things that you can do with Node.js!
If you find that Node.js isn't the language for you, removing it is as simple as the following:
yum remove nodejs -y
Kunstig intelligens er ikke i fremtiden, det er her lige i nuet I denne blog Læs, hvordan kunstig intelligens-applikationer har påvirket forskellige sektorer.
Er du også et offer for DDOS-angreb og forvirret over forebyggelsesmetoderne? Læs denne artikel for at løse dine spørgsmål.
Du har måske hørt, at hackere tjener mange penge, men har du nogensinde spekuleret på, hvordan tjener de den slags penge? lad os diskutere.
Vil du se revolutionerende opfindelser fra Google, og hvordan disse opfindelser ændrede livet for ethvert menneske i dag? Læs derefter til bloggen for at se opfindelser fra Google.
Konceptet med selvkørende biler til at køre på vejene ved hjælp af kunstig intelligens er en drøm, vi har haft i et stykke tid nu. Men på trods af flere løfter er de ingen steder at se. Læs denne blog for at lære mere...
Efterhånden som videnskaben udvikler sig i et hurtigt tempo og overtager en stor del af vores indsats, stiger risikoen for at udsætte os selv for en uforklarlig Singularitet. Læs, hvad singularitet kunne betyde for os.
Læs bloggen for at kende forskellige lag i Big Data-arkitekturen og deres funktionaliteter på den enkleste måde.
Opbevaringsmetoderne for dataene har været under udvikling, kan være siden fødslen af dataene. Denne blog dækker udviklingen af datalagring på basis af en infografik.
I denne digitalt drevne verden er smarte hjemmeenheder blevet en afgørende del af livet. Her er et par fantastiske fordele ved smarte hjemmeenheder om, hvordan de gør vores liv værd at leve og enklere.
For nylig udgav Apple macOS Catalina 10.15.4 en supplerende opdatering for at løse problemer, men det ser ud til, at opdateringen forårsager flere problemer, hvilket fører til mursten af mac-maskiner. Læs denne artikel for at lære mere