美文网首页
linux 下nodejs安装

linux 下nodejs安装

作者: 微嗔 | 来源:发表于2017-03-21 00:21 被阅读131次

一. nodejs 源码安装

1.  node js的源码包下载地址:http://nodejs.org/dist/,下载:wget http://nodejs.org/dist/v7.7.3/node-v7.7.3.tar.gz

2.  tar -zxvf node-v7.7.3.tar.gz && cd node-v7.7.3

3.  ./configure --prefix=prefix/nodejs &&  make -j8 && make install 

二、npm软件安装

1.  国内优秀的npm镜像

(1)  淘宝npm镜像

搜索地址 :http://npm.taobao.org/

registry地址:http://registry.npm.taobao.org/

(2)  cnpmjs镜像

搜索地址:http://cnpmjs.org/

registry地址:http://r.cnpmjs.org/

2. 临时使用npm镜像

(1)  示例一、npm --registry https://registry.npm.taobao.org install express

(2)  示例二、npm install -g cnpm --registry=https://registry.npm.taobao.org

(3)  示例三、npm --registry=http://registry.npm.taobao.org install -g node-gyp

3. 永久使用npm镜像

(1)  设置package的地址: npm config set registry "http://registry.npmjs.org/"

(2)  设置代理:

npm config set proxy http://server:port

npm config set https-proxy http://server:port

(3)  查看用户配置文件:npm config get userconfig,默认文件:$HOME/.npmrc

(4)  查看全局配置文件:npm config get globalconfig,默认文件:/usr/local/etc/npmrc

(5)  内置配置文件。安装npm的目录下的npmrc文件

三、npm的c++插件开发

1.  搭建npm c++插件开发环境

(1)  npm install -g node-gyp

(2)  编译安装:

node-gyp configure build 

注意:如果这个步骤特别的慢,可以手动下载相应的header文件,比如:

wget https://nodejs.org/download/release/v7.2.1/node-v7.2.1-headers.tar.gz

然后:解压, mv header目录到  ~/.node-gyp/7.2.1/include,最后:

echo "9" > ~/.node-gyp/7.2.1/installVersion

2.  Hello World

(1)  编写binding.gyp文件

关键配置target_name和sources文件

(2)  编写hello.cc 文件

关键函数:NODE_MODULE(addon, init)

关键函数:NODE_SET_METHOD(exports, "hello", Method);

3.  google的v8开发手册地址:http://bespin.cz/~ondras/html/classv8_1_1Value.html#a70d4afaccc7903e6a01f40a46ad04188

相关文章

网友评论

      本文标题:linux 下nodejs安装

      本文链接:https://www.haomeiwen.com/subject/dvjvnttx.html