How to install the Node. js module on Windows _ javascript tips-js tutorial

Source: Internet
Author: User
Node. js has gradually warmed up, and many friends have begun to pay attention to it. However, on Windows platforms, Cygwin-based installation and configuration environments are required, which can be discouraged by many users. However, it is reported that Microsoft has contacted the Node. js official website and I believe it will be improved soon.
If Cygwin is not installed, can I build a Node. js environment on Windows for trial development? I made a simple test with Node. js + express, which is basically feasible.
The procedure is as follows:

1. Download the Node. js official unstable version of Windows executable program:
Http://nodejs.org/#download
I used version 0.5.7 in the test: http://nodejs.org/dist/v0.5.7/node.exe

2. Create a c: \ nodejsdirectory and save node.exe in this directory.

3. Download express. Because of the dependency, we also need to download: connect, qs, mime, and jade (default express template system. If you are using another template system, you need to download the corresponding system)
Name address test version
---------------------------------------------------------------
Express: https://github.com/visionmedia/express 2.4.3
Connect: https://github.com/senchalabs/connect 1.7.1
Qs: https://github.com/visionmedia/node-querystring 0.3.1
Mime: https://github.com/bentomas/node-mime 1.2.4
Jade: https://github.com/visionmedia/jade 0.15.4

4. Create the c: \ nodejs \ node_modules directory, and create the [Module] Directory respectively in this directory. Compress the file downloaded in the previous step and copy the file to the [Module] Directory.
Node_modules
|-Connect <= connect: lib /*
|-Express <= express: lib /*
|-Jade <= jade: lib /*
|-Mime <= mime: mime. js & types /*
|-Qs <= qs: lib /*

5. Create the following files in the c: \ nodejs \ node_modules directory:
Connect. js
Content: module. exports = require ('./connect ');
Express. js
Content: module. exports = require ('./express ');
Jade. js
Content: module. exports = require ('./jade ');
Mime. js
Content: module. exports = require ('./mime ');
Qs. js
Content: module. exports = require ('./qs/querystring ');

6. Copy the bin/express file in the downloaded express package to the c: \ nodejs directory and change it to express. js.

7. Modify the express. js file. The following uses 2.4.3 as an example:
7.1. Modify the mkdir function body
401: exec ('mkdir-p' + path, function (err ){
-> Exec ('md '+ path, function (err ){
7.2. Modify the mkdir function call
263: mkdir (path + '/public/javascripts ');
-> Mkdir (path + '\ public \ javascripts ');
264: mkdir (path + '/public/images ');
-> Mkdir (path + '\ public \ images ');
265: mkdir (path + '/public/stylesheets', function (){
-> Mkdir (path + '\ public \ stylesheets', function (){
280: mkdir (path + '/view', function (){
-> Mkdir (path + '\ views', function (){

8. Create an express project:
C: \ nodejs \ node.exe express. js-s hello

9. c: \ nodejs \ node_modules \ *. * => c: \ nodejs \ hello \ node_modules \

10. Run and test:
C: \ nodejs \ node.exe hello \ app. js
Open http: // localhost: 3000 in the browser and view the result.

Now the test is complete.
The following is a test file. In the test file, I also tested express session. You can open http: // localhost: 3000/session in the browser to view the result.

Test File: nodejs.rar
Related Article

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.