本文演示在Linux上安装NodeJS及Express开发框架 nodejs和mongodb的更新速度太快。参考以前的老文章进行安装,但是用最新版本的nodejs的话,通常会出现很多问题。最新版本的nodejs解压就可以使用和运行,但是,为了更好的配置nodejs,我使用了nodejs 的v0.10.24版本进行安装。
具体安装过程如下:
[root@BobServerStation local]# yum -y install gcc gcc-c++ openssl-devel
[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
[root@BobServerStation node-v0.10.24]# ./configure --prefix=/usr/local/node [root@BobServerStation node-v0.10.24]# make && make install
[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
--重启生效
[root@BobServerStation node-v0.10.24]# node -v
v0.10.24
出现NodeJS版本号则表示OK。
[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
[root@BobServerStation local]# npm install express -g
[root@BobServerStation local]# express DemoApp
[root@BobServerStation local]# cd DemoApp
[root@BobServerStation DemoApp]#
[root@BobServerStation local]# cd DemoApp
[root@BobServerStation DemoApp]# npm install
方法一:通过config命令
npm config set registry http://registry.cnpmjs.org
npm info underscore (如果上面配置正确这个命令会有字符串response)
方法二:命令行指定
npm --registry http://registry.cnpmjs.org info underscore
方法三:编辑 ~/.npmrc 加入下面内容
registry = http://registry.cnpmjs.org
[root@BobServerStation DemoApp]# node app
Express server listening on port 3000
最后通过浏览器访问服务器3000端口,页面显示, Express Welcome to Express