node. JS Development Environment Setup (WINDOWS+LINUX)

Source: Internet
Author: User

I. Installing module management such as node. JS and Npm,mysql on the Windows platform

1. Download node. JS official Windows edition program and NPM

http://nodejs.org/#download

Https://github.com/isaacs/npm/tags

2. Create the D:\nodejs directory and save the Node.exe in this directory. The "D:\nodejs" is added to the system environment variable path, allowing the node application to be executed at any location.

3. Extract the NPM source code into the D:\NPMJS directory. perform the following operation in the Command Prompt window to complete the NPM installation

// the latest version of NPM can be installed  // can install the specified version of NPM the above two methods are downloaded and installed from the code base through the network, but the codebase generally retains only the last two versions. After the NPM installation is complete, add "D:\nodejs\node_modules" to the system environment variable Node_path to install Express:
npm Install express-g // Install the latest Expressnpm Install [email protected]/ /  Install the specified version Expressnpm Remove express-g // Delete Express But here it is important to note that express may have some limitations on the version I am installing 
NPM install [email protected] can use
// Create a exrpess project  // start

Open in Browser: http://localhost:3000, view the results.

Install MySQL

You first need to install the MySQL module into Nodejs, Nodejs use the unique NMP download module. In the command line
, point the command line to the installation directory for Nodejs. Enter the code:

$npm Install Mysql  

The downloaded module may not be in the Nodejs C:\Program files\nodejs\node_modules\npm folder, and my XP machine is downloaded to document.
, how to download the MySQL module folder is not found, you need to find it, copy it to the NMP folder.


First of all, install Nodejs MySQL package This is not much to say:

npm install mysql

In fact, the idea is very simple, that is, the connection mysql--Select the database-Execute SQL statements, but when I follow the online data began to write up, but found that the effect can not appear, command line error a bunch, MySQL is not connected. So I began to panic, and then slowly calm, start a line to view the code, online more than the link database require("mysql").Client to use, I have done so, so it is not.

Later thought of a soil method, first in the MySQL installation correct premise require ("MySQL") must be no problem, and then print out all the objects or properties under the module console.log (Require ( "MySQL") , this is a glance, you can not find the Client method, a closer look at a createconnection method, So words too literally began to use this method to try to connect MySQL, sure enough, OK, as follows:

  var   MQ  =    require   (  " MySQL "    var   MC  =  Span class= "PLN" > MQ   createconnection    user     span class= "str" > "root"    password  :     "xxxxxx"    });  MC   connect    

Look back and think about why the online method will fail? Perhaps because of the version update, some method names have also been replaced. The next step is to simply manipulate the database, which is the same as other languages:

mc.query("use database");mc.query("select * from table", function(err, rs, fields){    //处理数据});

Well, so far my basic purpose has been almost fulfilled.


node. JS Development Environment Setup (WINDOWS+LINUX)

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.