In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is to share with you what are the basic knowledge points of Node.js. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
What is Node.js?
According to the official website of Node.js, "Node.js is a platform built on the Chrome JavaScript runtime environment, designed to easily create fast and scalable web applications. Node.js uses an event-driven non-blocking iCandle O model, which makes it lightweight and efficient, making it ideal for data-intensive real-time applications running across distributed devices." It is recommended that before you start learning, read the article "what is Node,js" to gain an in-depth understanding of the definition of Node.js.
Node.js provides a complete set of solutions for server-side applications, such as the Web platform, and is able to communicate with other systems, including databases, LDAP, and any traditional application. Users can implement Node.js development in a variety of scenarios.
Installation proc
Node.js can run on Windows, Linux, and Mac platforms. It provides 32-bit and 64-bit platforms. To install Node.js in a Ubuntu Linux environment, you need to use the console and write the following script:
Sudo apt-get install python-software-properties
Sudo add-apt-repository ppa:chris-lea/node.js sudo apt-get update
Sudo apt-get install nodejs npm
To implement Node.js installation for other Linux platforms, it is recommended that you click here to visit GitHub for complete instructions.
If you belong to Windows users, you can use their installation files to complete the installation of Node.js. We can download the installation file from the official website of Node.js. According to the actual platform type, download the corresponding .MSI file, run it, and enter the installation dialog box shown below:
Follow the installation instructions to complete the process step by step.
After the installation is complete, a Node.js icon will be added to the Windows menu. If you click the icon in the menu, the Node.js console will open immediately.
You can run the Node.js console manually from the Windows command prompt (CMD). Reveal the command prompt interface and enter the following command:
Node
The interface will respond to the operation as the Node.js console.
Development tools
You can use any text editor to write Node.js code. If you want to gain more development experience, you can also take advantage of various code editors with rich features, such as WebStorm JetBrains, Eclipse, and Visual Studio. Some code editors may also provide debugging capabilities.
In Visual Studio 2012, you can use Web project templates, such as ASP.NETmpty site templates.
Visual Studio 2012 provides an IntelliSense feature designed to help users display explanatory information related to API and syntax.
Hello World
As a starting task to learn a new programming language, we usually start with writing "hello world" code. So Node.js is no exception, so let's start writing "hello world" under Node.js.
First, run our code editor and write the following:
Hello world console.log ('Hello world, nodejs')
Save the above code to a file named helloworld.js.
Next, open a command prompt or terminal (in Linux environment) and execute the file:
"node helloworld.js
The following is the output of our "hello world" application after running:
Node.js module
Node.js provides a variety of modules to help users complete the development work. With the support of the module, we can significantly reduce the number of lines of code that need to be written, thus greatly reducing the time consumption of development work.
There are a large number of Node.js modules available for everyone to use. Interested friends can click here to view the list page of Node.js modules in GitHub.
To install the Node.js module, you need the help of the Node Packged Modules (npm) package manager. After the Node.js installation is complete, we should already have the npm package manager. You can check whether it already exists by entering the following command:
Npm-help
Next, you will get a response in the console, as shown in the figure below:
Let's try to use a Node.js module, and as an example, we want to add color display to the console text. The required module is cli-color.
First, install the cli-color module:
Npm install cli-color
Note: when installing the Node.js module, your computer must be able to access the Internet connection, and some modules require the user to have administrator-level permissions when installing the module.
The output after installation is shown in figure 8:
So how do we use this module?
We need to invoke the desired Node.js module by calling the command require and the name of the target module:
Var clc = require ('cli-color')
Therefore, if we need to display the text content in color, we need to call xxx.blue to implement the blue text and xxx.green to implement the green text. Where xxx is the corresponding cli-color object.
Console.log (clc.blue ('"Hello node.js" in blue')); console.log (clc.red ('"Hello node.js" in red')); console.log (clc.green ('"Hello node.js" in green'))
You can see an example of the result of the program output in figure 9.
Update Node.js version
The next question is, how do we know what version of Node.js we are currently using?
You can use a Node.js command to get information about the current version of Node.js. Write the following script:
Please node-v
The following figure shows the output of the Node.js script:
Node.js does not automatically update the current runtime. You should check and update the Node.js version manually. Download the installation file from the official Node.js website and install it on your computer.
The installation process will check the Node.js that has been installed so far. If there is an installed Node.js, the installation tool upgrades the existing version of Node.js. After the installation is complete, please check our Node.js version again.
Thank you for reading! This is the end of this article on "what are the basic knowledge points of Node.js?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.