Nodejs在Linux的部署和配置

    xiaoxiao2021-03-25  58

    Linux centos-7系统,nodejsnode-v6.10.0-linux-x64

    1.nodejs官网(http://nodejs.cn/download/)下载压缩包选择合适自己系统的版本),放到Linux的安装目录下,

     

    2.tar -xvf node-v6.10.0-linux-x64解压下载的nodejs压缩包

     

    建议用mv node-v6.10.0-linux-x64 node移动重命名文件

    3.设置nodejs全局变量,

    ln -s /root/node/bin/node /sbin/node

    ln -s /root/node/bin/npm /sbin/node

                                                

    4.设置环境变量,在根目录下/etc/profile里面添加

    export node_home = /root/node

    export PATH = $node_home/bin:$PATH

     

    5.在工作目录下创建hello.js文件,在里面添加

    var http = require('http');

    http.createServer(function(req, res){

      res.writeHead(200,{'Content-Type': 'text/plain'});

      res.end('hello world');

    }).listen(3030);

    console.log("http server is listening at port 3030.");

                                                            

    7.node运行hello.js文件,

    node hello.js

     

    然后在浏览器输入IP地址加端口号输出内容了

    转载请注明原文地址: https://ju.6miu.com/read-39006.html

    最新回复(0)