Mac 安装nodejs

这几日因为需求需要又临时用到nodejs,之前安装过好几次,但是每次还是忍不住百度下,所以这次在此mark下 Mac 下 nodejs 的安装和检验,给自己留个标记,提高下以后的效率。


step 1:

Mac 安装nodejs


step 2:

  • 双击刚下载的文件,按步骤默认安装就行

Mac 安装nodejs


step 3:

  • 安装完成后打开终端,输入 
    npm -v 
    node -v 
    两个命令,如下图出现版本信息,说明安装成功。

Mac 安装nodejs


step 4:

  • 新建一个js文件,nodejsTest.js , 输入下面的代码, 并保存

var http = require("http");

http.createServer(function(request, response) {
    response.writeHead(200, {
        "Content-Type" : "text/plain"
    });
    response.write("Welcome to Nodejs");
    response.end();
}).listen(8000, "127.0.0.1");

console.log("Creat server on http://127.0.0.1:8000/");

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 打开终端进入 nodejsTest.js 所在目录, 输入 node nodejsTest

Mac 安装nodejs

Mac 安装nodejs

 

相关文章:

  • 2021-07-29
  • 2022-12-23
  • 2022-12-23
  • 2022-01-18
  • 2021-05-31
  • 2021-05-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-15
  • 2021-11-03
  • 2021-10-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案