zoukankan      html  css  js  c++  java
  • ubuntu安装nodejs

    使用apt安装nodejs,

    sudo apt install nodejs  

    安装npm

    apt install npm 

    源码安装 

    1.下载Nodejs源码

    http://nodejs.cn/download/

    wget -c  资源地址 

    -c表示当网络中断恢复后断点续传

    下载后解压,进入解压目录

    2.生成Makefile

    编译需要依赖python环境、c、c++

    apt install gcc

    apt install python

    ./configure --prefix=/usr/local/nodejs/

    运行python脚本

    3.make -j 4 && sudo make install

    安装make工具

    apt install make
    apt install make-guile

    -j 4 表示用4个线程去编译

    4.配置环境变量

    vi ~/.bashrc

    修改完后 source ~/.bashrc 使配置生效

    env | grep PATH

    env显示环境变量

    启动node

    node

    查看nodejs版本

    node --version

    最简单的http服务

    1.使用require引入http模块

    2.创建http服务

    3.侦听端口

    server.js

    'use strict'
    
    var http = require('http');
    
    var app = http.createServer(function(req,res){
        res.writeHead(200,{'Content-Type':'text/plain'});
        res.end('HelloWorld
    ');
    }).listen(8080,'0.0.0.0');

    启动Nodejs服务

    netstat -ntpl 查询所有tcp端口

    node app.js

    浏览器访问ip:8080  显示HElloWorld

    启动程序的三种方式

    node app.js

    nohub node app.js

    forever start app.js

    使用forever启动

    1.安装forever

    yum -y install forever -g 

    -g 表示在任何目录下使用forever,如果不加,只能在当前目录使用

    如果执行失败

    使用 npm config set strict-ssl false

    forever start server.js 启动服务

    forever stop server.js 关闭服务

    ssh root@IP 使用ssh连接

  • 相关阅读:
    如何挖掘需求,覆盖整个系统
    JVM全整理
    7.linux文件与目录管理
    6.linux的文件权限与目录配置
    获取外汇基本汇率
    Pointer-Events: 如何处理ScreenTouch和MouseClicks
    Excel如何快速定位出两列的不同值
    Java数据结构: java.util.BitSet源码学习
    一道面试题与Java位操作 和 BitSet 库的使用
    Test post.
  • 原文地址:https://www.cnblogs.com/dch0/p/11110489.html
Copyright © 2011-2022 走看看