Home > Web Front-end > JS Tutorial > body text

How to install Node.js modules on Windows_javascript tips

WBOY
Release: 2016-05-16 18:01:53
Original
1182 people have browsed it

However, there is news that Microsoft has contacted Node.js officials, and I believe there will be improvements soon.
So without installing Cygwin, is it possible to set up a Node.js environment on Windows for experimental development? I did a simple test using Node.js express, and it is basically feasible.
The steps are as follows:

1. Download the official non-stable Windows executable program of Node.js:
http://nodejs.org/#download
I used 0.5 in the experiment .7 version: http://nodejs.org/dist/v0.5.7/node.exe

2. Create the c:nodejs directory and save node.exe in this directory

3. Download express. Because of dependencies, we also need to download: connect, qs, mime and jade (express default template system. If you use other template systems, you need to download the corresponding system)
Name Address Experimental 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:nodejsnode_modules directory, and create [Module] directories in this directory. Then compress the file downloaded in the previous step and copy the relevant files to the [Module] directory.
node_modules
|- connect |- express |- jade |- mime |- qs
5. In the c:nodejsnode_modules directory, create the following files:
connect.js
Content: module.exports = require('./connect/connect');
express.js
Content: module.exports = require('./express/express');
jade.js
Content: module.exports = require('./jade/jade');
mime.js
Content: module.exports = require('./mime/mime');
qs .js
Content: module.exports = require('./qs/querystring');

6. Copy the bin/express file in the downloaded express compressed package to the c:nodejs directory, and Rename to express.js

7. Modify the express.js file, taking 2.4.3 as an example below:
7.1. Modify the mkdir function body
401: exec('mkdir -p ' path, function(err){
->exec('md ' path, function(err){
7.2. Modify 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 '/views', function(){
->mkdir(path '\views', function(){

8. Create an express project:
c:nodejsnode.exe express.js -s hello

9. c:nodejsnode_modules*.* => c:nodejshellonode_modules

10. Run and test:
c:nodejsnode.exe helloapp.js
Open in browser: http://localhost :3000 to view the results.

The test is now completed.
The test file is given below. In the test file, I also tested express session. You can open it in the browser: http://localhost:3000/session to view the results.

Test file: nodejs.rar

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template