I started watching nodejs last weekend. I encountered some problems from installation to getting started code. Today I finally solved a problem and wrote it down to share it:
Installation:
1.First of all, my system is Windows 8, so here we will only talk about the installation steps of node in windows. The node is: http://nodejs.org/download/
You can see that Windows has two types of installation files: EXE files and MSI files. The difference is that MSI needs to be installed, and relevant execution files will be written to system environment variables after installation, and
Other node plug-ins, such as NPM, are also integrated.
But when I installed the MSI file and installed express again, I encountered a problem. If you don't want to hide it, download a node.exe file.
2.In D: \, create a folder named nodejs to put the downloaded node.exe file under this folder. After a pure node environment is installed, press shift in the current directory and right-click it,
Select to open the command line tool in the current directory.
> Node-V outputs the version information to verify whether the installation is successful.
> View the help information of node-H and list the usage of several simple commands.
Try to write path D: \ nodejs into the path of the system environment variable to execute the node command in any place.
3.Install NPM. This tool should be a plug-in management tool, which will be dependent on later on the plug-in, so you must install it first.
Download this file: https://github.com/isaacs/npm/zipball/v1.0.104 in D: \ nodejs \ create npmjs directory, download the file decompress to npmjs, such.
There is a node_modules folder, and the folder in it is empty. Download a new node_modules from here and replace the previous one.
4.Open the command line tool in the D: \ nodejs \ npmjs folder and execute> node install NPM-GF (when I do this step, remind me that the version is incorrect, 0.4, 0.5, and 0.6 versions should be used,
I switched to node.exe of version 0.6so that NMP is installed)
Run> NPM-V to check whether the version is successfully installed.
5.Install Express. Open CMD in the D: \ nodejs directory and execute NPM install express-G. Note: the installation process is a bit long and you have to wait patiently. Don't think that failure is the result of no response.
Run> express-VCheck whether version Verification is installed successfully. Note that V is in uppercase.
Most of the above steps are based on the articles by park friends Sean LV. However, due to some problems still encountered during the copy operation, I reorganized and added several problems I found by myself.
6.This step is to install a small tool: formidable. I used it in the following exercises, so I 'd like to write it here.
Run the "NPM install formidable" command to complete the installation. Note: If the node.exe version used is too high, the installation will fail, and the version 0.9 or below is required.
Nodejs entry:
The following describes how to get started with nodejs. Here I recommend an online book "getting started with node" at http://www.nodebeginner.org/index-zh-cn.htmlwhich many people will recommend.
This book is well written.However, it is quite uncomfortable that many Chinese compatriots directly paste their articles into their blogs to install B.. In fact, I just read this book this evening, but now I have met it.
I would like to share with you the following content if you did not read this book to get started.
1.The following function is described in the book:
function sleep(milliSeconds) { var startTime = new Date().getTime(); while (new Date().getTime() < startTime + milliSeconds);}
Where while (new date (). gettime () <starttime + milliseconds); I am a bit blind. The while loop can still be written like this. Is the code wrong? After execution, it is found that this is okay, but every
Only no operation is determined for the next loop.
2.Server. listen (1, 8888 ). to listen to the port, but when you repeat the request multiple times, there will be a conflict, resulting in node command error, then change the port number, I changed 8821, 8823 and so on.
3.When performing non-blocking processing, exec ("find/", function (error, stdout, stderr ){...}). One of the Parameters "find/" refers to the commands in Linux, and of course "ls-lah ".
If you operate in windows, an error must be reported here. You can replace it with "dir.
4.In the later example of uploading images, when var form = new formidable. incomingform () is executed, it always fails. Later, it was found that it was a version problem. I downloaded the Version 1.0
Overwrite the previous one, and this place will pass.
5.In the same example, FS. renamesync (files. Upload. path, "/temp/test.png"); returns an error. renamesync is easy to use with rename. The real reason is described in the following article.
Finally, I just called out all the code and found an article on the Internet to analyze the shortcomings of this book. It would be nice to see it early, haha. Below is the link. We recommend that you:
Http://cnodejs.org/topic/4f348e5ec420ea662d026df2
Finally, I was just beginning to try to write node, hope to communicate with you a lot ah, my Weibo is: http://weibo.com/319111988