Mac下nodeJS初体验


Mac下nodeJS初体验

这两天博主出门在外,抽空体验一下大名鼎鼎的node

安装

brew install node

安装测试

$ node -v
v8.4.0

运行本地脚本

用文本编辑器编辑一段js脚本,测试提供的Javascript环境

helloworld.js

$ node helloworld.js
Hello World
3

用node命令也可以进入交互式shell模式。

helloworld

helloworld.js

// 载入http模块
var http = require("http")
// 创建服务器
http.createServer(function(request, response){
    //发送HTTP头部
    //HTTP状态:200:OK
    //内容类型:text/plain
    response.writeHead(200,{'Content-Type': 'text/plain'});
    //发送响应数据
    response.end("Hello World!");
}).listen(8000); //服务器在8000端口监听
//终端打印信息
console.log("Server running at http://127.0.0.1:8000/");

用node运行脚本后,在本地浏览器访问http://127.0.0.1:8000/就可以看到helloworld了。

初体验先到此为止,开发工具的话推荐VScode


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM