Let’s talk about nodejs first. Some people think it is a language, but it is not. It is a platform, a js running platform built on Google’s V8 engine, which parses js and provides some of its own APIs for users to call. Judging from the current situation, the development is pretty good. Many front-end and back-end engineers will join tomorrow, and even some great masters are paying attention and even writing blogs. Last night, I saw an article that a foreign website wrote about nearly 90 web plugins for nodejs. This is so awesome! What benefits can we bring most directly to learn Chinese things? Because front-end personnel are familiar with JS, they can basically learn Linux and get started. Back-end engineers are a little troublesome, because some back-end engineers are not familiar with JS and may have many obstacles to using them. It is recommended to learn basic JS here. After talking about this, I think the salary issue should be the issue. So far, nodejs engineers who have been more than one year have already offered a price of more than 7K in Guangzhou. This is also a colleague of the past said that his company recruitment situation. I realized that this thing is close to hadoop! Let’s stop here. Let’s talk about this topic: environment configuration (since I was developed under Windows 8.1, I will only talk about Windows here).
Install nodejs
First, go to the nodejs official website http://www.nodejs.org/download/ to download the corresponding version. Mine is 64-bit. After downloading, install it directly. Since the current version has reached v0.10.33, node and npm have been installed together, and even the environment variables have been set. After installation, you can see the following in the corresponding folder.
After installation, you can use Shift + right-click to open cmd in the currently installed folder. Enter the following to view the installed version. My name is 0.10.32.
node-v
2. Global folder settings
As for node_cache and node_global, it should not be set for beginners, because it will be set to the current user directory, but sometimes it will also be set for it for convenience. The following commands provided here are as follows:
npmconfigls//list prefix configurationnpmconfigsetcache'D:/ProgramFiles/nodejs/node_cache'//Set global cache folder
npmconfigsetcache'node_global'//Set global module folder
3. Install the module
Now we have installed node and npm. As the name suggests, npm is the node's package manager. It is managed through commands. Let's try it now:
Let's install a web framework express. The parameter -g means to be installed in the global folder. If it is not present, it means the current folder
npminstallexpress-g//express can also bring @ version number
Now we are checking in the folder we just set up. Is there any more files? Here we use the command to view the version number of the express just installed just now.
express-V
If there is an output version, it means the installation has been successful!
If we want to uninstall this plugin, we can use the following command
npmuninstallexpress
After uninstalling this way, we install back to express, but we will bring the version number 3.2.2 (because this is the version I am most familiar with). Will this be possible?
4. Use express to install
Now we use commands to create a web site, as follows:
expressTest
This will output some prompts, you can jump into the Test folder and run this site with the command:
nodeapp.js
I saw the prompt, port 3000 indicates that it was launched successfully, but our browser browsing errors, what are the prompts?
500 Error: Cannot find module 'jade'
There is a prompt that an error is reported. Let's install this module now. Here is an explanation. There is a package.json file in this folder. This file describes some site information. We can use nodepad to open it:
This means that two libraries are needed, one is express, and the other is Jade. So let's install it now. If many modules are installed, wouldn't it take many commands to be executed? Here is a command that is relatively simple, which will check the current package.json dependency library for installation:
npminstall
After installing this module, we also need to modify the doctype 5 in the first line of the layout.jade file under views to change it to doctype html. In this way, re-execute node app.js and our website can run normally.
5. Install the supervisor plugin
We may have discovered just now that if something goes wrong, nodejs will automatically stop the service, which is not conducive to debugging. Then we have a plug-in to solve it. This plugin is a process that manages nodejs, and it is very useful, including debugging. Use the following command to install the global module:
npminstallsupervisor-g
In this way, we don’t use the node command to start the service, just use the supervisor app.js.
6. Use webStorm IDE
We just edited the js file using nodepad, but this is not very good. Is there a good editor? The answer is yes, a big-name webStorm, which has many downloads of that version on the Internet. Everyone understands it. Here is a link provided by netizens http://yunpan.cn/cAcf6hVxnIbCt Extraction Code 246f. After downloading, install it directly. Just overwrite an exe file after installation. It’s so simple!
The first time you run it, you will open a folder, which is actually the folder of the project.
Let’s talk about the debugging problem, including I have been working on it for a long time and searched it online for a long time. Finally, Bo Ge told me that it was done. This is actually very difficult to simple, so I just look at the picture:
How to debug by breaking points in the program, it is very convenient.
The above is a complete record of my personal experience in the configuration and use of nodejs development environment. I will continue to share some detailed applications of nodejs in the future.