Javascript 如何判断是否安装了 node.js

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10475651/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 01:32:02  来源:igfitidea点击:

How to tell if node.js is installed or not

javascriptnode.js

提问by user1340052

I've recently installed node.js and I have no idea how to run applications. I installed node.js but couldn't find further instructions. What does one really need to do? I wanted to see if it was actually working. So I executed a script called hello.js. It went as such:

我最近安装了 node.js,但不知道如何运行应用程序。我安装了 node.js 但找不到进一步的说明。一个人真正需要做什么?我想看看它是否真的有效。所以我执行了一个名为 hello.js 的脚本。它是这样的:

console.log('hello world');

Now where would this be logged to?

现在这将被记录到哪里?

Edit

编辑

I'm running this .js through a .php script.

我正在通过 .php 脚本运行这个 .js。

回答by Piotr Tomasik

Open a terminal window. Type:

打开终端窗口。类型:

node -v

This will display your nodejsversion.

这将显示您的nodejs版本。

Navigate to where you saved your script and input:

导航到您保存脚本和输入的位置:

node script.js

This will run your script.

这将运行您的脚本。

回答by mehmet riza oz

open a terminal and enter

打开终端并输入

node -v

this will tell you the version of the nodejs installed, then run nodejs simple by entering

这将告诉您安装的 nodejs 的版本,然后通过输入运行 nodejs simple

node

Prompt must be change. Enter following,

提示必须更改。输入以下,

function testNode() {return "Node is working"}; testNode();

command line must prompt the following output if the installation was successful

如果安装成功,命令行必须提示如下输出

'Node is working'

回答by shijinmon Pallikal

Please try this command node --versionor node -v, either of which should return something like v4.4.5.

请尝试此命令node --versionnode -v,其中任何一个都应返回类似v4.4.5.

回答by James Wierzba

(This is for windows OS but concept can be applied to other OS)

(这适用于 Windows 操作系统,但概念可以应用于其他操作系统)

Running command node -vwill be able to confirm if it is installed, however it will not be able to confirm if it is NOT installed. (Executable may not be on your PATH)

运行命令node -v将能够确认它是否已安装,但如果未安装它将无法确认。(可执行文件可能不在您的 PATH 中)

Two ways you can check if it is actually installed:

您可以通过两种方式检查它是否已实际安装:

  1. Check default install location C:\Program Files\nodejs\
  1. 检查默认安装位置 C:\Program Files\nodejs\

or

或者

  1. Go to System Settings -> Add or Remove Programsand filter by node, it should show you if you have it installed. For me, it shows as title:"Node.js" and description "Node.js Foundation", with no version specified. Install size is 52.6MB
  1. 转到System Settings -> Add or Remove Programs并按 过滤node,它应该显示您是否安装了它。对我来说,它显示为标题:“Node.js”和描述“Node.js Foundation”,没有指定版本。安装大小为 52.6MB

If you don't have it installed, get it from here https://nodejs.org/en/download/

如果你没有安装它,从这里获取它https://nodejs.org/en/download/

回答by Bacar Pereira

Ctrl+ R- to open the command line and then writes:

Ctrl+ R- 打开命令行,然后写入:

node -v

回答by Siva Prakash

Open the command prompt in Windows or terminal in Linux and Mac.Type

在 Windows 中打开命令提示符或在 Linux 和 Mac 中打开终端。键入

node -v

If node is install it will show its version.For eg.,

如果安装了节点,它将显示其版本。例如,

v6.9.5

Else download it from nodejs.org

否则从nodejs.org下载

回答by Abdullah Khan

Check the node version using node -v. Check the npm version using npm -v. If these commands gave you version number you are good to go with NodeJsdevelopment

使用node -v. 使用npm -v. 如果这些命令给了你版本号,你就可以继续NodeJs开发了

Time to test node

测试节点的时间

Create a Directory using mkdir NodeJs. Inside the NodeJsfolder create a file using touch index.js. Open your index.jseither using vior in your favourite text editor. Type in console.log('Welcome to NodesJs.')and save it. Navigate back to your saved file and type node index.js. If you see Welcome to NodesJs.you did a nice job and you are up with NodeJs.

使用mkdir NodeJs. 在NodeJs文件夹内使用touch index.js. index.js使用vi或在您喜欢的文本编辑器中打开您的文本编辑器。输入console.log('Welcome to NodesJs.')并保存。导航回您保存的文件并键入node index.js. 如果你发现Welcome to NodesJs.你做得很好,并且你已经适应了 NodeJs。