Nodejs decompressed version installation and environment configuration

WBOY
Release: 2023-05-08 19:16:36
Original
2786 people have browsed it

With the rapid development of Node.js, it has become one of the favorite server-side environments for JavaScript developers. Node.js is designed to be non-blocking and event-driven, which allows it to handle large amounts of I/O operations without causing blocking. Use Node.js to quickly build highly scalable web applications such as websites, APIs, and real-time communications applications. In this article, we will learn how to install and configure an unpacked Node.js environment.

  1. Download Node.js

First, you need to visit the official website of Node.js (https://nodejs.org/en/) and go to the download page Select the unzipped version of Node.js. Choose the correct version based on your operating system. For example, for Windows 64-bit operating system please download "Windows Binary (.tar.xz) 64-bit". When the download is complete, extract the installation package to any location on your local drive.

  1. Configuring environment variables

The decompressed version of Node.js requires manual configuration of environment variables to make the command line tool node and NPM commands available in any folder.

(a) Windows environment variables

Open Control Panel->System and Security->System->Advanced System Settings->Environment Variables. In System Variables, select the "Path" option and edit it. Use the "New" button to add the Node.js installation path, for example: "D:
odejs", and then save the changes.

(b) Linux environment variables

When you unpack Node.js on a Linux system, you need to edit the .bashrc file to configure the environment variables. To edit the .bashrc file, use the following command:

$ sudo nano ~/.bashrc

Add the following line at the bottom of the file:

export PATH=$PATH: /opt/nodejs/bin

Save the file and execute the following command to load the .bashrc:

$ source ~/.bashrc

Now you can access node and NPM from the terminal Order. Run the following command to check if they are available:

$ node -v

$ npm -v

If you successfully installed and configured the environment variables, you will see the installed Node.js and NPM version numbers.

  1. Using Node.js

Using the unpacked Node.js installer, you can now use Node.js to develop JavaScript-based web applications. By using Node.js, you can create server-side applications by creating JavaScript modules that contain network requests, I/O operations, and other functionality. In this section, we will introduce some important concepts of Node.js and write a simple "Hello World" application.

(a) Writing a "Hello World" Application

Open a console or terminal in a location of your choice and enter the following code:

$ mkdir myapp

$ cd myapp

$ echo "console.log('Hello World')" > app.js

After installing Node.js, you need to create a new folder ( For example "myapp"), and create a file named app.js, add the following code in it:

console.log('Hello World');

(b) Run the application Procedure

In the console or terminal, run the application using the following command:

$ node app.js

If you see the output of "Hello World!" So you have successfully run a simple Node.js application! congratulations!

(c) More complex applications

Now you have the basics of creating and running a simple Node.js application. You can combine other Node.js modules to achieve richer functions, or use some popular frameworks such as Express development to take full advantage of Node.js.

Conclusion

In this article, we introduced in detail how to install and configure the environment of the unpacked version of Node.js, and showed how to write and run Node.js applications. If you want to delve deeper into Node.js, please refer to the official Node.js documentation, or use other resources in the community. Node.js is a very powerful and widely used technology, and more and more companies and communities are actively contributing and developing it.

The above is the detailed content of Nodejs decompressed version installation and environment configuration. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template