Mac 安装 node.js

2023-07-23  本文已影响0人  iVikings
  1. 下载安装

1.1 官网下载
https://nodejs.cn/

1.2 nvm 下载安装
1.2.1 安装 nvm

brew install nvm

1.2.2 安装 nodejs
安装 14.15.3 版本的 node.js

nvm install 14.15.3

nvm 常用命令

nvm list

nvm list installed
nvm list available
nvm install 14.15.3
nvm install latest
nvm use 14.15.3
nvm uninstall 14.15.3
nvm arch
nvm on
nvm off
nvm proxy [url] 
nvm version

  1. 执行下面两个命令验证
npm -v
node -v
  1. 安装 yarn
sudo npm install --global yarn

使用 npm 初始化项目

mkdir video
cd video
npm init
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 Node.js\n');
});

server.listen(port, hostname, () => {
    console.log(`Server running at http://${hostname}:${port}/`);
});
node app.js
上一篇 下一篇

猜你喜欢

热点阅读