Nodejs installation and configuration under Windows system

Source: Internet
Author: User

about Nodejs Chinese station, now the best active knowledge station should be http://www.cnodejs.org/, and http://cnodejs.org/is less active. Express.js is an MVC development framework for NODEJS and supports a variety of templates such as Jade, which is the most popular web development framework on node. js. These days just contact PhoneGap, once also looked at some Nodejs foundation but suffering from limited time has not had the opportunity to build a NODEJS environment, today, the weekend, deployed PhoneGap to Android, by the way together to build a nodejs local environment, Your own operating procedures such as the following:

1th Step: Download, install files

On behalf of Nodejs's official website http://www.nodejs.org/download/Download the latest version number, after downloading, double-click Node-v0.10.20-x86.msi, start the installation Nodejs, the default is installed in C:\Program Files\nodejs folder. After installation, the system default environment variable path is C:\Documents and settings\administrator\application data\npm; You can manually point to the local installation folder as required, such as: C:\Program FILES\NODEJS\NODE_MODULES\NPM set the Global folder setting to the local initial default installation folder.


2nd step: Install the relevant module environment


Open the C:\Program Files\nodejs folder you'll find that it comes with NPM, the management tool for the Nodejs plugin, which can be installed directly with NPM (some other systems may need to be installed separately npmhttps:// GITHUB.COM/ISAACS/NPM, you can also download git clone--recursive directly with Git tools git://github.com/isaacs/ Npm.git after the download is complete, the command line first navigates to the folder where the NPM package is located, and the Input Code node cli.js install NPM-GF installs. )

System Start Menu--Program--Enter the node. js Command Prompt commands form

Type the command: CD C:\Program Files\nodejs to enter the Nodejs installation folder C:\Program Files\nodejs

Start installing the relevant module environment now

Node module installation is divided into global mode and local mode. Normally it will be executed in local mode, and the package will be installed in the local Node_modules folder with your app code statistics. In global mode, the node package is installed under node_modules under node's default installation folder.

The first method is to type the command: The latest version number of the default installation express for NPM install Express. If you add a version number later, you can install the specified version number, such as NPM install [email protected] Enter to start the installation of Express, after installation will be in the current directory Node_ Modules Catalog Express and. bin for the two + Express related categories.

Another way to install the global installation is to type the command: NPM install express-g, the command line prompts NPM info OK. The meaning of the count-G is to represent the installation into the global environment. Assuming that there is no-G, it will be installed into the current Node_modules directory (if none is new Node_modules directory). Individuals do not recommend the beginning of learning to use such a package installation to the global environment, because in the JS instance code, directly through the require () way is no way to call the global installation package, error throw err; Error:cannot find module ' Express ' allows you to copy the entire Node_modules directory to your project. The global installation is for the command line, and after the global installation, the user can execute the command directly on the command line that the package supports, with the advantage of being able to increase the reuse of the program and avoid multiple copies of the same content. The disadvantage is that it is difficult to handle different version number dependencies. The Require () is a node. js built-in function that introduces other modules to the code to invoke the functions and variables of the module, and by default, node. JS will look for modules in the Node_modules directory under the Node_path and current JS project directory. Therefore, assuming a global installation, do not replicate the system installation Node_modules directory into the project Node_modules directory, you can also choose to set the NODE_PATH environment variable to C:\Program Files\nodejs, After the setup is complete, go to the project folder and execute the command node App.js will not error. Express.js inherits from the Connect module, so it is not possible to do so if you do not have a connect module under your Node_modules folder.
Above for himselfSummary of Experience。 Later access to the documentation found a more specific response abroad:
Quoting Marek's question Error:cannot the answer to find module ' Express ':

This problems seems to be quite popular among Windows users. It seems to occur after node have been reinstalled or updated or when hidden attribute have been removed from C:\Users\IMa  Ster\appdata folder. It might be one of those things so can make you feel bad especially if you don ' t wont to apply some quick hacks like:n PM Link Express

Node returns error because is not able to the find required module and that's why problem in most cases are actually easy to f IX. First place-to-check would be require.paths. After typing it in node console I received:
Error:require.paths is removed. Use Node_modules folders, or the NODE_PATH environment variable instead.

At the time of writing I am using v0.6.19 and you might see this or similar warning if you using newer version.

As stated you have 2 choices. You can install Express (or another module) to the local node_modules directory using NPM install Express or after installing Module globally

NPM Install Express-g

You can link it with your current project using

NPM Link Express

Second and last option was to create or update node_path system variable pointing your NODE to the right place in the Syst Em. If You is Windows user use Export command as shown below:

Export node_path= "C:\Users\IMarek\AppData\Roaming\npm\node_modules"

Now, should update PATH variable as well

Set path=%path%;%node_path%

Try to run your module now.

You should be fine.

After the express installation is completed, the node app.js browser input http://localhost:3000 can be previewed to indicate the successful installation of Express.

Here is an indication that express Error:cannot find module ' Jade ' shows that the Jade module is not installed and Windows does not have to manually download the jade package, which is already integrated (assuming other places are needed, you can download it here https://github.com /visionmedia/jade). Enter NPM install Jade to mount it.
After the jade installation is complete

About express.js Chinese Guide manual can participate in http://www.csser.com/board/4f77e6f996ca600f78000936
There are many other components, such as MySQL, that can be installed according to individual needs.
By default, components are installed in the C:\Program Files\nodejs\node_modules directory, which is also the active lookup path for NODEJS related components.

3rd Step: Test Projects Project

Now that the express component is installed, try typing: Express MyApp builds a project named MyApp, with a single MyApp folder under the folder.
The need to copy the Node_modules directory to MyApp is determined by the above NPM Express installation method

Create a new helloworld.js under MyApp, such as the following code:


var http = require ("http"); Http.createserver (function (request, response) {Response.writehead (), {"Content-type": " Text/plain "}"); Response.Write ("Hello World"); Response.End ();}). Listen (8080); Console.log (' Server running at http://127.0.0.1:8080/');


Enter the node. js command prompt commands form and go to the C:\Program Files\nodejs\myapp folder

Type node Helloworld.js

Browser input http://localhost:8080 or address http://127.0.0.1:8080/

Page output: Hello World

4th Step: Install Supervisor improve Nodejs commissioning efficiency

This step is not necessary, just to improve the Nodejs development efficiency of the auxiliary operation. In the past, we developed PHP projects, each time the code changes, can directly open the browser preview effect, do not need to manually restart the service. However, the development of Nodejs program, debugging, no matter what part of the code you changed, you need to restart the service talent to take effect. This is because node. JS only has the first reference to a part to parse the foot.
This file, will be directly to the memory, to avoid repeated loading. This design of node. JS, while improving performance, is not conducive to debugging, because we always want to see the effect in the development process, instead of terminating the process and restarting it every time. Supervisor can help you implement this feature by monitoring your code changes and proactively restarting node. js.

Supervisor is also very easy to install:

Install directly with NPM either, type the command: NPM install SUPERVISOR-G and then the program itself downloads the supervisor installation package locally to start the installation.

Note here that supervisor must be installed to the global, assuming you are not installing to the global, the error command will prompt you to install to the global.

Assuming that you do not want to install to the default global, you can also change the global path to the current path

NPM config set prefix "path"

After installation, you can use supervisor to start the service.

Supervisor App.js

Add: NPM often uses commands

(1) npm install Modulenames

Installing the Node module

Note: Assume that you do not know the name when using the module, you can pass the http://search.npmjs.org site according to

Index value to find the desired module. NPM also provides the functionality of the query NPM search IndexName

When the installation is complete, a Node_modules folder is created, and the individual node modules are installed under the folder.

Node installation is divided into global mode and local mode. Normally it will be executed in local mode and the package will be installed

To the local Node_modules folder with your app code statistics. In global mode, the node package is

Install to the Node_modules under node's installation folder. The Global installation command is

NPM install-g modulename. Learned to use NPM set Global=true to set the installation mode

, NPM get Global is able to view the installation mode currently in use. NPM Install <name>--save at the same time, write information to Package.json

When you leave a Package.json file in the project path, you can use the NPM install method to install all the dependent packages based on the dependencies configuration

When this code is submitted to GitHub, it is not necessary to submit the Node_modules directory.


(2) NPM view Modulenames

View the Package.json directory of the node module

Note: If you want to view the contents of a tag in the Package.json directory, you can use

NPM View ModuleName LabelName

(3) NPM list

View the node packages that are already installed under the current folder. With command npm ll/npm ls/npm LA

Note: The node module search is started from the current folder where the code is running, and the search results depend on the folder currently in use

The content under the Node_modules. NPM List Parseable=true is able to display folders in the form of

Pre-installed all node packages

(4) NPM Help

View the help command. If you want to view the help of the install command separately, you can use the NPM helper install

(5) NPM View moudlename dependencies

To view the dependencies of a package

(6) NPM View ModuleName Repository.url

View the source file address of a package

(7 NPM View ModuleName engines

View the version number of the node that the package depends on

(8) NPM Help folders

See all the catalogs used by NPM

(9) NPM rebuild ModuleName

Rebuild after changing package contents

(+) NPM outdated

Check if the package is obsolete, this command will list all obsolete packages and be able to update the package in a timely manner.

(one) NPM update modulename

Update Node Module

($) $ npm Uninstall Moudlename

Uninstalling the Node module

(13) A NPM package is included in the Package.json directory, Package.json describes the structure of this directory. Visitors

The method for asking NPM's JSON directory is as follows:

NPM Help JSON

This command opens a Web page by default, assuming that changing the default open program may not be a Web page

Open.

(14) When you publish a NPM package, you need to verify that a package name already exists.

NPM Search PackageName

(15) A lot of times when we use a NPM package, we often forget the require of its interdependent modules, and we can

See what packages this module depends on, such as the following commands



NPM init will guide you through the creation of a Package.json file containing the name, version number, author information, etc.

(+) NPM rm <name> Remove, uninstall a module. There are several command forms:
NPM RM <name>
NPM R <name>
NPM Uninstall <name>
NPM un <name>



NPM root View the installation path of the current project package, NPM root-g is the installation path to view the global package

NPM Docs <packageName> Try the appropriate document URL for the current package and open the document using a browser.

(+) NPM config? Get profile information, such as environment variables, NPMRC files, Package.json

Many other commands please refer to official documents https://npmjs.org/doc/

Documentation for this article:

1. Error:cannot find module ' Express ' http://blog.i-evaluation.com/2012/09/17/error-cannot-find-module-express/
2. node. js Manual & Documentation http://nodejs.org/docs/v0.4.1/api/modules.html
3. Nodejs-win http://code.google.com/p/nodejs-win/
4. Nodejs Official documentshttps://npmjs.org/doc/
The following is an extension link:
Node + Redis = Fun Http://howtonode.org/node-redis-fun
node. js Homestead Http://nodejs.gamesys.net/page/11
Nodejs Open Source Application http://obullxl.duapp.com/

Nodejs installation and configuration under Windows system

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.