node的安装与hello world

来源:互联网 发布:淘宝卖家宣传语 编辑:程序博客网 时间:2024/05/05 21:03

一、mac安装node:

  1.使用homebrew安装即可:

brew install node

  2.安装成功后,可以使用以下命令查看node的版本:

node -v


二、创建hello world的web程序:

  1.创建一个hello.js文件,写入:

var http = require('http');server = http.createServer(function (req, res) {res.writeHeader(200, {"Content-Type": "text/plain"});res.end("Hello World\n");});server.listen(8000);console.log("httpd start @8000");
  2.cd到此js所在的目录,然后执行:

node hello.js

  3.打开浏览器,输入localhost:8000即可以看到hello world

0 0
原创粉丝点击