Study materials
1. Easy to understand Node.js
2.Node.js Development Guide
Introduction (I only picked up what I think is important)
Node.js is a platform that allows Javascript to run on the server without the browser, not a language;
The Javascript engine used by Node.js is V8 from Google Chrome; if you run outside the browser, you don't have to consider the problem of Javascript compatibility.
Using single-threaded, asynchronous IO and event-driven designs to achieve high concurrency (asynchronous events also increase the difficulty of development and debugging to a certain extent);
Node.js has a built-in HTTP server, so it is good news for website development;
Home page: http://nodejs.org/
English API: http://nodejs.org/api/ (Latest)
Chinese API: http://nodeapi.ucdok.com/#/api/
Install Node.Js
Operating system environment: WiN 7 64-bit
Installation is relatively simple in Windows environment
http://nodejs.org/download/
Download the corresponding operating system installation file in the link (just install the latest version)
Follow the prompts and follow the next step until the installation is successful, you can see it in the default installation path (C:/Program Files/nodejs). The default path can be modified during installation.
After the installation is successful, enter: node -v in the "Command Prompt" to view the installation version, and the output version will be successful.
Introduction to NPM
The Node.js installation package for Windows contains Node Pageaged Modules https://npmjs.org/ (npm). This node.js itself has basic modules. With this npm, you can install rich node.js libraries to complete actual development requirements.
Commonly used commands:
View Help
npm help or npm h
Install the module
npm install <Module Name>
Install modules in a global environment (-g: enable global mode)
npm install -g <Module Name>
More: https://npmjs.org/doc/install.html
Uninstall the module
npm uninstall <Moudle Name>
Display the modules installed in the current directory
npm list
After the installation is successful, npm and node.js paths will be added to the PATH user environment variable and the system environment respectively.
Development Tools
WebStorm I downloaded 7.0, and it seems to be a lot of them
WebStorm download address: http://www.jetbrains.com/webstorm/
Those who do .NET development can choose WebMatrix3, download and install it directly. It is very convenient to operate without explaining too much. After using it for a while, you can directly build a Nodejs project. If you only develop it in the Windows environment, it is recommended to use it.
WebMatrix download address: http://www.microsoft.com/web/webmatrix/
I finally chose Sublime, which can maintain a unified development tool under each platform, and there are many configuration methods on the Internet
Sublime download address: http://www.sublimetext.com/ (The software does not require registration. A window that needs to be registered will pop up from time to time during use, just cancel it)
Sublime Node.js development environment configuration
Download and install the Node.js installation package before starting configuration
1. Install Sublime Text 2 first
2. Run Sublime and find Tools ---> Build System ---> new Build System
3. Copy in the file
The code copy is as follows:
{
"cmd": ["node", "$file"],
"file_regex": "^[ ]*File /"(...*?)/", line ([0-9]*)",
"selector": "source.javascript"
}
4. Save the file as NodeJs.sublime-build
5. Find Tools --->Build System --->Select NodeJs on the menu
6. Install Package Control; run Sublime, press the shortcut key Ctrl + `; enter the following in the console and press Enter;
The code copy is as follows:
import urllib2,os,hashlib; h = '7183a2d3e96f11eeadd761d777e62404' + 'e330c659d4bb41d3bdf022e94cab3cd0'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); os.makedirs(ipp ) if not os.path.exists(ipp) else None; urllib2.install_opener( urllib2.build_opener( urllib2.ProxyHandler()) ); by = urllib2.urlopen( 'http://sublime.wbond.net/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); open( os.path.join( ipp, pf), 'wb' ).write(by) if dh == h else None; print('Error validating download (got %s instead of %s), please try manual install' % (dh, h) if dh != h else 'Please restart Sublime Text to finish installation')
7. After the installation is completed, restart Sublime, press the shortcut key Ctrl + Shift + P; enter install, select Install Package and press Enter
8. Enter nodejs and select Nodejs installation (you can install JavaScript & NodeJs Snippets)
9. Create a new test.js file, enter console.log('Hello Node.js'); Press the shortcut key Ctrl + B to run, and the output will be successful! The following figure
The Sublime Node.js development environment is configured here and it will be successful!
If you want a better theme color scheme, please refer to: http://www.infoq.com/cn/minibooks/nodejs
Extension: Install multiversion manager
Install the multi-version manager nvmw (NVM used in the Node Development Guide book, seems not possible on Windows. I found this in www.npmjs.org. Although I can't use it for learning, install it first)
Installation command
npm install -g nvmw
Since it has not been used, I will not give any more introductions and view them in detail
https://npmjs.org/package/nvmw