美文网首页我爱编程
node.js 安装与配置

node.js 安装与配置

作者: Vincent_Jiang | 来源:发表于2017-03-30 22:04 被阅读26次

    版本说明

    • 偶数位为稳定版本
    • 奇数位为非稳定版本
    稳定版本 非稳定版本
    v0.6x v0.7x
    v0.8x v0.9x
    v0.10x v0.11x

    Windows 下安装

    下载地址:node.js中文网

    Mac 下安装

    • 终端下输入:brew install node
    • 目前版本的 node.js 会自动安装 npm 包管理器

    查看版本

    $ node -v
    v7.8.0
    
    $ npm -v
    4.2.0
    

    快速开始

    • 新建 server.js 并输入以下内容
    const http = require('http');
    
    const hostname = '127.0.0.1';
    const port = 3000;
    
    const server = http.createServer((req, res) => {
      res.statusCode = 200;
      res.setHeader('Content-Type', 'text/plain');
      res.end('Hello World\n');
    });
    
    server.listen(port, hostname, () => {
      console.log(`服务器运行在 http://${hostname}:${port}/`);
    });
    
    • 在当前目录下打开终端,输入 node server.js
    • 打开浏览器,在地址栏输入 127.0.0.1:3000,回车即可看到 Hello World

    更新

    • 更新已安装的 npm 库,npm update -g
    • 更新 node 本身,npm install -g n,再输入 n latest

    相关文章

      网友评论

        本文标题:node.js 安装与配置

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