美文网首页我爱编程
mac安装使用node.js

mac安装使用node.js

作者: NoException | 来源:发表于2017-03-03 11:21 被阅读0次

    1.安装node.js

    确保mac电脑上已经安装homeBrew,使用下面命令安装node.js

    brew install node

    检测版本

    node -v

    2.使用node.js开发web程序

    再目录/User/mac/test下编写node.js的测试文件test.js,内容如下

    var http = require('http');

    var data = {key:'value',hello:'hello'};

    var srv = http.createServer(function(req,res){

    res.writeHead(200,{'Content-type':'application/json'});

    res.end(JSON.stringify(data));

    });

    srv.listen(8080,function(){

    console.log('listening on localhost:8080');

    });

    以上代码将监听8080端口的http请求

    3.运行node.js

    到/User/mac/test/目录下启动node.js,执行命令:

    node test.js

    浏览器访问查看返回

    http://localhost:8080/

    至此我们已经完成了node.js的安装,下面我们使用intellij来编写nodeJs程序,需要配置以下插件:

    4.intellij集成nodeJs插件

    preference-》plugins-》install jetBrains plugins-》输入node,选择nodeJs(javaScript)

    相关文章

      网友评论

        本文标题:mac安装使用node.js

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