Node. js Development Environment configuration and use _ node. js-js tutorial

Source: Internet
Author: User
After several weeks of nodejs learning, I have gradually become familiar with nodejs from the beginning to the present. Now I have mastered the relevant learning methods, record your learning process today for future viewing. Let's talk about nodejs first. Some people think it is a language. Actually, it is not. It is a platform. A js running platform built on google's V8 engine is parsing js, and provide some APIs for users to call. Judging from the current situation, this development is still quite good. There will be many front-end backend engineers joining us tomorrow, and even some great gods are paying attention to or even writing blogs, last night, I also saw an article writing that a foreign website has written nearly 90 web plug-ins for nodejs. This is really awesome! So what are the most direct benefits for us to learn about Chinese Dongdong? The front-end staff can get started with linux simply because they are familiar with js, background engineers are a little troublesome, because some background engineers are not familiar with js usage, which may cause many obstacles. Here we suggest you study the basic js, after talking about this, I think it should be about salary. Up to now, nodejs engineers who have been operating in Guangzhou for more than yuan have already offered a price, this was also the case when a former colleague said that he was recruiting from the company. I only knew that this was a direct force on hadoop! Let's talk about this. Next, let's talk about this topic: Environment configuration (because I developed it in windows 8.1, I will only talk about it in windows ).

Install nodejs

Go to the official nodejs website http://www.nodejs.org/download/download the corresponding response. I am 64-bit. After the download, install the tool directly. Because the current version has already reached v0.10.33, node and npm have been installed together and the environment variables have been set, after installation, you can see the following in the corresponding folder:

After the installation is complete, you can right-click the cmd in the currently installed folder and enter the following to view the installed version, which is 0.10.32.

node-v

Ii. Global folder settings

Node_cache and node_global should not be set for beginners, because they will be set to the current user directory, but sometimes they will also set it for convenience, the following command is provided:

Npmconfigls // list prefix configurations
Npmconfigsetcache 'd: \ ProgramFiles \ nodejs \ node_cache '// sets the global cache folder.
Npmconfigsetcache 'node _ global' // sets the global module folder.

Iii. Installation Module

Now we have installed node and npm. As the name suggests, npm is the node Package Manager, which can be managed through commands. Now let's try:

We will install a web framework express. The parameter-g indicates that the package is installed in the global folder. If not, it indicates the current folder.

Npminstallexpress-g // express can also contain the @ version number.

Now we can check whether there are some files in the folder we just set. Here we use the command to check the version number of the express installation just now.

express-V

If an output version exists, the installation is successful!

If we want to uninstall this plug-in, we can use the following command:

npmuninstallexpress

In this way, we will install the SDK back to express after uninstalling the SDK. However, the later version is 3.2.2 (because the most familiar version is this). Will this happen?

4. Install with express

Run the following command to create a web site:

expressTest

In this way, some prompts will be output. You can directly jump into the Test folder and run the site using the command:

nodeapp.js

No prompt displayed. port 3000 indicates that the startup is successful, but the browser reports an error. What is the prompt?

500Error: Cannot find module 'jade'

If an error is reported, we will install this module now. Here, we will describe that there is a package in this folder. json file, which describes some site information. You can use nodepad to open it:

This shows that two libraries are needed, one is express and the other is jade. Now we will install it. If many modules are installed, we will not execute many commands, here is a simple command that checks the current package. install json dependent libraries:

npminstall

After installing this module, we also need to modify layout under views. change doctype 5 in the first line of the jade file to doctype html. then re-execute the node app. js. This website can run normally.

5. Install the supervisor plug-in

We may have all just discovered that, if a problem occurs, nodejs will automatically stop the service, which is not conducive to debugging. We have a plug-in to solve this problem. This plug-in is used to manage nodejs processes, including debugging which are very useful. Run the following command to install the global module:

npminstallsupervisor-g

In this way, you don't need the node command to start the service. You can simply use the supervisor app. js.

6. Use webStorm IDE

Just now, we used nodepad to edit the js file. But this is not very good. Is there a good editor? The answer is yes. A famous webStorm is used for download of many versions on the Internet, everyone understands, here also provides a netizen to the link http://yunpan.cn/cAcf6hVxnIbCt extraction code 246f, download directly installed, installed to overwrite an exe file can be, diaosi so simple!

The first running will open a folder, which is actually the project folder.

Next, let's talk about the debugging problems, including I have been online for a long time and I have been searching for it for a long time. Finally, I can talk about it in bogo. This is actually very difficult and easy to understand:

It is very convenient to debug the program by hitting a breakpoint.

The above is a full record of my experiences in configuring and using the node. js development environment. I will continue to share some detailed nodejs Applications later.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.