mac 安装node.js_如何在Windows,Mac或Linux上安装Node.js

mac 安装node.js

In this tutorial, I’ll be teaching you how you can install Node.js on windows, mac or linux in under 15 minutes.

在本教程中,我将教您如何在15分钟内在Windows,Mac或Linux上安装Node.js。

Node is an open-source runtime environment for javascript. It is a cross-platform environment providing its support for Mac, Windows and Linux. It runs Chrome’s V8 javascript engine, outside the browser, and because of this, it is very powerful.

Node是javascript的开源运行时环境。 它是一个跨平台环境,提供对Mac,Windows和Linux的支持。 它在浏览器外部运行Chrome的V8 javascript引擎,因此它非常强大。

It runs in a single process, without creating a new thread for every request. Node JS

它在单个进程中运行,无需为每个请求创建新线程。 节点JS

节点应用程序外观如何? (How Does a Node App Look?)

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 World');
});
 
server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

如何安装Node.js? (How to Install Node.js?)

These tools are required for developing a Node.js application on any platform.

在任何平台上开发Node.js应用程序都需要这些工具。

  • Node JS

    节点JS

  • Node Package Manager or NPM*

    节点程序包管理器或NPM *
  • A text editor or an IDE

    文本编辑器或IDE

*NPM gets installed automatically when you install Node on your system.

*在系统上安装Node时,会自动安装NPM。

在Windows和MAC上安装 (Installation on Windows and MAC)

To download node, you just need to visit the node’s official website and download the LTS version of node.

要下载节点,您只需要访问该节点的官方网站并下载该节点的LTS版本。

Once, downloaded, you’ll see an installer similar to this.

下载完成后,您将看到与此类似的安装程序。

node js installer

Hit install it as you install any other application on your Windows or Mac. Enter your system password if prompted.

在Windows或Mac上安装任何其他应用程序时,请点击安装。 如果出现提示,请输入系统密码。

node js installer

And once done, the installer will prompt you a success message. You can now go ahead and delete the installer.

完成后,安装程序将提示您成功消息。 现在,您可以继续并删除安装程序。

node js installer

在Linux上安装 (Installation on Linux)

To install Node on your Ubuntu machine, run the following command:

要在Ubuntu计算机上安装Node,请运行以下命令:

curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - sudo apt-get install -y nodejs

Once you download Node, the NPM or Node Package Manager automatically gets installed as it also ships with the node.

下载节点后,将自动安装NPM节点软件包管理器,因为它也随节点一起提供。

安装文本编辑器 (Installing the Text Editor)

The next thing is to install a text editor which will help you in writing code. The one which I personally use is Visual Studio Code by Microsoft.

接下来是安装一个文本编辑器,它将帮助您编写代码。 我个人使用的是Microsoft的 Visual Studio Code

You can download it from here: https://code.visualstudio.com/

您可以从这里下载: https : //code.visualstudio.com/

Once you are done with the text editor, the next thing which you can do is to check whether the path of the Node is correct or not.

使用文本编辑器完成操作后,下一步是检查Node的路径是否正确。

测试Nodejs和NPM安装 (Testing Nodejs and NPM installation)

You can check your node installation just by running a small node command which will show you the version installed. Just open your cmd or PowerShell and paste the below command. This will show the version of node installed on your computer.

您可以通过运行一个小的node命令来检查您的节点安装,该命令将向您显示安装的版本。 只需打开您的cmd或PowerShell,然后粘贴以下命令。 这将显示您计算机上安装的节点的版本。

node -v
v12.16.0

Similarly, you can check the version of npm installed on your computer. Just paste the below node command to check the version.

同样,您可以检查计算机上安装的npm的版本。 只需粘贴以下node命令以检查版本。

npm -v
v6.13.4

运行您的第一个应用程序 (Running Your First App)

Here you are all set up, let’s try to run a small node server. Open VS Code and create a new file and save it as app.js

在这里,您已经完成了所有设置,让我们尝试运行小型节点服务器。 打开VS Code并创建一个新文件,并将其另存为app.js

Now paste the following code.

现在粘贴以下代码。

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 World');
});
 
server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

Now save the code and hit Ctrl + ~

现在保存代码,然后Ctrl + ~

This will open an integrated terminal of vs code in the same directory and from here you can directly run your js code.

这将在同一目录中打开vs代码的集成终端,从这里您可以直接运行js代码。

Simply run the following command and hit enter.

只需运行以下命令,然后按Enter。

node app.js
Server running at http://127.0.0.1:3000/

You can now visit http://127.0.0.1:3000/ to check your node app running.

您现在可以访问http://127.0.0.1:3000/来检查节点应用程序的运行情况。

Well, this was all about setting up your system for js development. If you stuck into any kind of error, don’t forget to google it and try to debug it on your own.

好了,这就是为js开发设置系统。 如果您遇到任何类型的错误,请别忘了用Google搜索并尝试自行调试。

This will teach you how to debug on your own as someone might have faced a similar problem earlier.

这将教您如何自行调试,因为之前可能有人遇到过类似的问题。

If you still don’t find any solution for your problem, you can ask your doubt in the comment’s section below and we’ll get back to you.

如果您仍然找不到解决问题的方法,可以在下面的评论部分中提出疑问,我们将尽快与您联系。

翻译自: https://www.thecrazyprogrammer.com/2020/04/how-to-install-node-js.html

mac 安装node.js

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PythonNode.js是两种不同的编程语言和运行环境,它们之间没有直接的安装关系。Python是一种通用的编程语言,而Node.js是基于JavaScript的运行时环境。 如果你想在Python使用Node.js的功能,可以通过使用相关的Python库来实现。例如,可以使用`nodejs`库来在Python中执行JavaScript代码。你可以使用以下命令来安装`nodejs`库: ``` pip install nodejs ``` 安装完成后,你可以在Python代码中导入`nodejs`库,并使用它来执行JavaScript代码。 然而,如果你只是想单独安装Node.js,而不是在Python使用它,你需要按照Node.js的官方文档提供的方式进行安装。以下是在不同操作系统上安装Node.js的一般步骤: - 在Windows安装Node.js: 1. 访问Node.js官方网站(https://nodejs.org/)。 2. 下载适用于WindowsNode.js安装程序(.msi文件)。 3. 运行下载的安装程序,并按照提示进行安装。 - 在Mac安装Node.js: 1. 使用Homebrew进行安装:打开终端并运行以下命令: ``` brew install node ``` 2. 使用Node.js官方安装程序进行安装:访问Node.js官方网站(https://nodejs.org/),下载适用于MacNode.js安装程序(.pkg文件),然后运行安装程序并按照提示进行安装。 - 在Linux安装Node.js: 1. 使用包管理器进行安装:根据你使用Linux发行版,运行适当的命令来安装Node.js。例如,在Ubuntu上可以运行以下命令: ``` sudo apt-get install nodejs ``` 2. 使用Node.js官方安装程序进行安装:访问Node.js官方网站(https://nodejs.org/),下载适用于LinuxNode.js安装程序(.tar.gz文件),然后按照官方文档提供的步骤进行安装。 希望以上信息对你有帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值