linux nodejs express,CentOS安装NodeJS及Express开发框架

https://blog.csdn.net/weixin_39952502/article/details/117512160

为了更好的配置nodejs,我使用了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

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

                                                   npm install -g express-generator

 

 

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、安装依赖组件npm的时候,出错的话,请运行如下命令(npm国内镜像)

方法一:通过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

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

[root@BobServerStation DemoApp]# node app

Express server listening on port 3000

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

Express

Welcome to Express

Step12、配置3000端口,将项目发布到my-app文件夹,启动访问

http://192.168.4.125:3000/my-app/

posted on 2022-07-07 08:51  四海骄阳  阅读(71)  评论(0编辑  收藏  举报

导航