错误版本(未更新前的安装方法,更新后就不是这么安装了,好多网上的教程还是这种方法,所以这里先写明了,旧版这里是可以通过的,但是新版4.x就不行了,请用分割线下边的方法)

 
本文演示在Linux上安装NodeJS及Express开发框架

 
软件环境:
VMware 9
CentOS 6.5
NodeJS v0.10.24
 
安装过程:

Step 1、确认服务器有nodejs编译及依赖相关软件,如果没有可通过运行以下命令安装。

[root@BobServerStation local]# yum -y install gcc gcc-c++ openssl-devel

Step 2、下载NodeJS源码包并解压。

[root@BobServerStation local]# wget http://nodejs.org/dist/v0.10.24/node-v0.10.24.tar.gz

[root@BobServerStation local]# tar zxvf node-v0.10.24.tar.gz
[root@BobServerStation local]# cd node-v0.10.24
Step 3、配置、编译、安装。

[root@BobServerStation node-v0.10.24]# ./configure --prefix=/usr/local/node

[root@BobServerStation node-v0.10.24]# make && make install
将持续3-4min....
 
Step 4、接下来配置Node环境

[root@BobServerStation node-v0.10.24]# vim /etc/profile

#set nodejs env
export NODE_HOME=/usr/local/node
export PATH=$NODE_HOME/bin:$PATH
export NODE_PATH=$NODE_HOME/lib/node_modules:$PATH
 
[root@BobServerStation node-v0.10.24]# source /etc/profile       --重启生效
 
Step 5、测试是否安装成功

[root@BobServerStation node-v0.10.24]# node -v

v0.10.24

出现NodeJS版本号则表示OK。
 
Step 6、NodeJS之Hello World

[root@BobServerStation node-v0.10.24]# node

> console.log(”Hello NodeJS, I'm Bob.Z“);

Hello NodeJS, I'm Bob.Z

undefined

>

输出:Hello NodeJS, I'm Bob.Z
 
Step 7、安装Express开发框架

[root@BobServerStation local]# npm install express -g

 
Step 8、创建Demo项目

[root@BobServerStation local]# express DemoApp

[root@BobServerStation local]# cd DemoApp

[root@BobServerStation DemoApp]#

 
Step 9、进入项目目录并安装项目依赖组件

[root@BobServerStation local]# cd DemoApp

[root@BobServerStation DemoApp]# npm install

 
Step 10、依赖组件安装完成后启动app

[root@BobServerStation DemoApp]# node app

Express server listening on port 3000

 
最后通过浏览器访问服务器3000端口,页面显示,

Express

Welcome to Express

 
Node + Express成功运行,顺利开启Node开发之旅,enjoy it!
 
我本地按教程进行安装的结果
 

在官网找到了解决方法是 express 4需要通过 下面的命令安装

npm install -g express-generator

-------------------------------------------------------------分割线-----------------------------------------------------------------------------
 
新版4.x的安装方法
首先,我们需要安装express库。在Express3.6.x之前的版本,Express需要全局安装的,项目构建器模块是合并在Express项目中的,后来这个构建器被拆分出来,独立成为了一个项目express-generator,现在我们只需要全局安装express-generator项目就行了。
[root@localhost nodejs]# npm install -g express-generator
/root/git/nvm/versions/node/v4.2.1/bin/express ->/root/git/nvm/versions/node/v4.2.1/lib/node_modules/express-generator/bin/express
express-generator@4.13./root/git/nvm/versions/node/v4.2.1/lib/node_modules/express-generator
├── sorted-object@1.0.
├── mkdirp@0.5.(minimist@0.0.)
└── commander@2.7.(graceful-readlink@1.0.)
至此,express就安装完成了。
安装好express-generator包后,我们在命令行就可以使用express命令了,如下。
[root@localhost DemoApp]# express -V
4.13.
[root@localhost DemoApp]# express -h
Usage: express [options][dir]
Options:
-h,--help output usage information
-V,--version output the version number
-e,--ejs add ejs engine support (defaults to jade)
--hbs add handlebars engine support
-H,--hogan add hogan.js engine support
-c,--css <engine> add stylesheet <engine> support (less|stylus|compass|sass)(defaults to plain css)
--git add .gitignore
-f,--force force on non-empty directory
现在可以开始创建项目了,如下:express DemoApp
[root@localhost nodejs]# express DemoApp
create :DemoApp
create :DemoApp/package.json
create :DemoApp/app.js
create :DemoApp/public
create :DemoApp/public/javascripts
create :DemoApp/public/images
create :DemoApp/public/stylesheets
create :DemoApp/public/stylesheets/style.css
create :DemoApp/routes
create :DemoApp/routes/index.js
create :DemoApp/routes/users.js
create :DemoApp/views
create :DemoApp/views/index.jade
create :DemoApp/views/layout.jade
create :DemoApp/views/error.jade
create :DemoApp/bin
create :DemoApp/bin/www
install dependencies:
$ cd DemoApp&& npm install
run the app:
$ DEBUG=DemoApp:* npm start
创建完项目,系统提示需要安装依赖,进入项目目录,下载依赖并安装,如下:cd DemoApp/&& npm install
[root@localhost nodejs]#cd DemoApp/&& npm install
cookie-parser@1.3. node_modules/cookie-parser
├── cookie@0.1.
└── cookie-signature@1.0.
debug@2.2. node_modules/debug
└── ms@0.7.
serve-favicon@2.3. node_modules/serve-favicon
├── etag@1.7.
├── fresh@0.3.
├── ms@0.7.
└── parseurl@1.3.
morgan@1.6. node_modules/morgan
├── on-headers@1.0.
├── basic-auth@1.0.
├── depd@1.0.
└── on-finished@2.3.(ee-first@1.1.)
express@4.13. node_modules/express
├── escape-html@1.0.
├── merge-descriptors@1.0.
├── cookie@0.1.
├── array-flatten@1.1.
├── cookie-signature@1.0.
├── utils-merge@1.0.
├── content-type@1.0.
├── methods@1.1.
├── vary@1.0.
├── etag@1.7.
├── path-to-regexp@0.1.
├── serve-static@1.10.
├── range-parser@1.0.
├── content-disposition@0.5.
├── fresh@0.3.
├── parseurl@1.3.
├── depd@1.0.
├── qs@4.0.
├── proxy-addr@1.0.(forwarded@0.1., ipaddr.js@1.0.)
├── finalhandler@0.4.(unpipe@1.0.)
├── on-finished@2.3.(ee-first@1.1.)
├── type-is@1.6.(media-typer@0.3., mime-types@2.1.)
├── send@0.13.(destroy@1.0., statuses@1.2., ms@0.7., mime@1.3., http-errors@1.3.)
└── accepts@1.2.(negotiator@0.5., mime-types@2.1.)
body-parser@1.13. node_modules/body-parser
├── content-type@1.0.
├── bytes@2.1.
├── depd@1.0.
├── qs@4.0.
├── on-finished@2.3.(ee-first@1.1.)
├── http-errors@1.3.(statuses@1.2., inherits@2.0.)
├── iconv-lite@0.4.
├── type-is@1.6.(media-typer@0.3., mime-types@2.1.)
└── raw-body@2.1.(unpipe@1.0., bytes@2.2., iconv-lite@0.4.)
jade@1.11. node_modules/jade
├── commander@2.6.
├── character-parser@1.2.
├── void-elements@2.0.
├── mkdirp@0.5.(minimist@0.0.)
├── constantinople@3.0.(acorn@2.7.)
├── clean-css@3.4.(commander@2.8., source-map@0.4.)
├── jstransformer@0.0.(is-promise@2.1., promise@6.1.)
├── transformers@2.1.(promise@2.0., css@1.0., uglify-js@2.2.)
├── with@4.0.(acorn@1.2., acorn-globals@1.0.)
└── uglify-js@2.6.(async@0.2., uglify-to-browserify@1.0., source-map@0.5., yargs@3.10.)
启动项目服务 :npm start
root@localhost DemoApp]#npm start
>DemoApp@0.0. start /root/nodejs/DemoApp
> node ./bin/www
GET /200382.317 ms -
GET /stylesheets/style.css 20017.834 ms -
GET /favicon.ico 40456.666 ms -
GET /favicon.ico 40439.911 ms -
GET /30458.911 ms --
GET /stylesheets/style.css 3041.839 ms --
GET /30447.751 ms --
GET /stylesheets/style.css 3040.280 ms --
GET /30453.378 ms --
GET /stylesheets/style.css 3040.258 ms --
 
如果发现express 版本为2.x怎么办?
需要对express进行升级,执行命令
npm install express --save
 

安装4.x版本的express开发框架的更多相关文章

  1. CentOS安装NodeJS及Express开发框架

    http://zhaohe162.blog.163.com/blog/static/38216797201402234212981/   express 命令行工具 npm install -g ex ...

  2. 安装了SQL2005再安装SQL 2008R2,提示此计算机上安装了 Microsoft Visual Studio 2008 的早期版本和检查是否安装了 SQL Server 2005 Express 工具的解决方案

    工作电脑上安装了SQL 2005, 但是客户电脑上安装的是SQL 2008R2,有时候连接他们的库调试没法连接,很不方便.然后又安装了个SQL2008 R2,期间遇到这两个问题,网上搜索了一下收到了解 ...

  3. 一台电脑安装多个版本的jdk

    我们平时在做Java开发的时候,有时需要使用多个版本的jdk, 那么一台电脑上需要安装多个JDK了. 那一台电脑上可不可以同时安装多个版本的jdk呢? 答案是可以的! 但使用的时候,只能使用一个,不能 ...

  4. 检测计算机已经安装的NetFramework版本(摘录)

    /// /// 检测计算机已经安装的NetFramework版本 /// internal void GetVersionFromRegistry() { using (RegistryKey ndp ...

  5. window下在同一台机器上安装多个版本jdk,修改环境变量不生效问题处理办法

    window下在同一台机器上安装多个版本jdk,修改环境变量不生效问题处理办法 本机已经安装了jdk1.7,而比较早期的项目需要依赖jdk1.6,于是同时在本机安装了jdk1.6和jdk1.7. 安装 ...

  6. 查看已安装的CentOS版本信息:

    如何查看已安装的CentOS版本信息: 1)[root@localhost ~]# cat /proc/version Linux version 2.6.18-194.el5 (mockbuild@ ...

  7. Mac下同时安装多个版本的JDK

    JDK8 GA之后,小伙伴们喜大普奔,纷纷跃跃欲试,想体验一下Java8的Lambda等新特性,可是目前Java企业级应用的主打版本还是JDK6, JDK7.因此,我需要在我的电脑上同时有JDK8,J ...

  8. Window 中安装python多版本环境

    由于python 3 已是目前稳定,且是将来版本版本.新学者可以直接从python3入手学习.但是目前还有很多企业级应用使用的是python 2,可能还得要维护.所以,我们在本地windows中可以安 ...

  9. Linux系统启动流程及安装命令行版本

    Debian安装 之前也安装过很多次linux不同版本的系统,但安装后都是直接带有桌面开发环境的版本,直接可以使用,正好最近项目不是很忙,想一直了解下Linux的整个启动流程,以及如何从命令行模式系统 ...

随机推荐

  1. 整不明白Jquery的问题

    最近写个GridView,由于不是很熟悉javascript,用jquery实现后,发现下面设置左右表行高的代码如果不把行保存在$tr1,$tr2中再设置css,速度非常慢,300行50列左右的数据得 ...

  2. ZendFramework2 源码分析 init_autoloader.php

    // Composer autoloading if (file_exists('vendor/autoload.php')) { // 加载自动加载器 $loader = include 'vend ...

  3. 负载均衡集群之LVS持久链接

    原理--> 通过构建一个hash表,利用CIP与RS的对应关系,来保持来自一个CIP的各种服务都走同一个RS 目的--> 保持持久链接的同时,将多个服务合并起来,例如http和https ...

  4. wordpress教程之自带缩略图功能

    首页你要看下你所用的主题有没有开启文章缩略图功能,如果看起的话,会在wordpress后台编辑页面或者文章时在右下角的地方看到一个特色图像的设置,如下图: 如果没有说明你还没有激活这功能.我们需要在你 ...

  5. 处理事件的方式:两种类的覆盖处理(自己管理,覆盖专用事件函数;自己统一管理,覆盖QWidget::Event通用函数),一种对象的处理(父控件统一管理,即安装过滤器),两种全局处理(QCoreApplication安装过滤器;覆盖notify方法)

    虽然只有一句话,但却是我自己的心得. 特别注意,bool QCoreApplication::notify(QObject *receiver, QEvent *event) 明确指明了要发送的对象, ...

  6. Ring3下Hook NtQueryDirectoryFile隐藏文件

    NTSTATUS WINAPI Hook_NtQueryDirectoryFile(IN HANDLE FileHandle,IN HANDLE Event OPTIONAL,IN PIO_APC_R ...

  7. Arcgis api For silverlight 加载高德地图

    原文 http://www.cnblogs.com/thinkaspx/archive/2012/11/13/2767752.html 地图仅供演示,研究使用.如要商用 请联系厂商. public c ...

  8. 窗口变化相关消息 OnSize、OnSizing和OnGetMinMaxInfo

    最近用到窗口变化的一些东西,遇到几个相关的消息函数,简要分析,作为备忘. 3个消息分别是:WM_SIZE.WM_SIZING.WM_GETMINMAXINFO:分别对应相应的处理函数:OnSize.O ...

  9. Roy the Robber

    Problem Description The aspiring Roy the Robber has seen a lot of American movies, and knows that th ...

  10. 三十二、Java图形化界面设计——布局管理器之CardLayout(卡片布局)

    摘自 http://blog.csdn.net/liujun13579/article/details/7773945 三十二.Java图形化界面设计--布局管理器之CardLayout(卡片布局) ...