mac node repl_带有Node REPL(CLI)和Node IDE的Node JS基本示例

mac node repl

In previous post, we have already spent some time on setting up Node JS Base environment. Now we will discuss about how to use Node CLI (Command Line Interface) or Node REPL(Read-Eval-Print Loop) to write and execute some basics Scripts and also discuss about Node JS IDE to write and execute simple Java Script files.

在上一篇文章中,我们已经花了一些时间来设置Node JS Base环境。 现在,我们将讨论如何使用Node CLI(命令行界面)或Node REPL(Read-Eval-Print Loop)来编写和执行一些基本脚本,并讨论Node JS IDE来编写和执行简单的Java Script文件。

Brief Post Content:

简报内容

  • Login and Exit into/from Node CLI

    登录和退出Node CLI
  • Execute Simple JavaScript Commands from Node CLI

    从节点CLI执行简单JavaScript命令
  • Execute JS Files from Node CLI

    从Node CLI执行JS文件
  • Node IDE Setup

    节点IDE设置
  • Develop Node JS project from Node IDE

    从Node IDE开发Node JS项目
  • Execute Node JS project from Node IDE

    从Node IDE执行Node JS项目

从节点CLI登录/退出 (Login to/Exit from Node CLI)

Open command prompt anywhere in your filesystem and execute “node” to login to Node CLI as show below;

在文件系统中的任何位置打开命令提示符,然后执行“ node”以登录到Node CLI,如下所示;

Use process.exit() command to exit from Node CLI as show below.

使用process.exit()命令退出Node CLI,如下所示。

执行简单的JS命令 (Execute Simple JS Commands)

We can execute any JavaScript code one by one from Node CLI as show below.

我们可以从Node CLI一对一执行任何JavaScript代码,如下所示。

Output: Hello JournalDEV users

输出 :Hello JournalDEV用户

Like this, we can run commands/statements from Node CLI directly and we can see the output on console.

这样,我们可以直接从Node CLI运行命令/语句,并且可以在控制台上看到输出。

执行Java脚本文件 (Executing Java Script Files)

Now we will discuss about “How to run JavaScript file that is ‘*.js’ files from Node CLI”.

现在,我们将讨论“如何从Node CLI运行JavaScript文件* .js”。

If we want to run more statements at Node CLI, then we need to run them one by one. But if we write those statements into a JS file, we can run them with just single command. We need to use “node” command to run JS files from Node CLI.

如果要在Node CLI上运行更多语句,则需要一个一个地运行它们。 但是,如果我们将这些语句写入JS文件,则只需一个命令即可运行它们。 我们需要使用“ node”命令从Node CLI运行JS文件。

Syntax:

nodejs-run-js-file

Here <JS-Filename> is our Java Script filename.

语法

这里的<JS-Filename>是我们的Java脚本文件名。

For example, write sample.js file.

例如,编写sample.js文件。

var helloJDMessage = "Hello JournalDEV users";
console.log(helloJDMessage);

Use simple Text Editor or any Java Script editor to write this code.

使用简单的文本编辑器或任何Java脚本编辑器来编写此代码。

Open command prompt at “D:\NodeJSExamples” and run “Sample.js” file as shown below.

在“ D:\ NodeJSExamples”处打开命令提示符,然后运行“ Sample.js”文件,如下所示。

Here we can observe that we are able to print message to console when we run our Sample.js file with node command.

在这里,我们可以观察到,使用node命令运行Sample.js文件时,便能够将消息打印到控制台。

So far we have discussed about how to write simple JavaScript files by using some Text Editor. It’s ok to write some simple programs and for practice purpose.

到目前为止,我们已经讨论了如何使用一些文本编辑器编写简单JavaScript文件。 可以编写一些简单的程序并用于实践目的。

However as a Developer, It’s not good practice to use Text Editors. We should use some Node IDE (Integrated Development Environment) or Tools to ease the Development process and also to reduce Development time and effort.

但是,作为开发人员,使用文本编辑器不是一个好习惯。 我们应该使用一些Node IDE(集成开发环境)或工具来简化开发过程,并减少开发时间和精力。

Now onwards, we are going to use a Node IDE known as “Eclipse Node.js IDE”. Eclipse Node.js IDE is simply known as Enide Studio. In Enide, “E” stands for Eclipse, “n” stands for Node JS and “ide” stands for IDE. We will use Enide latest version “Enide IDE 2014”.

现在开始,我们将使用称为“ Eclipse Node.js IDE”的Node IDE。 Eclipse Node.js IDE简称为Enide Studio。 在Enide中,“ E”代表Eclipse,“ n”代表Node JS,“ ide”代表IDE。 我们将使用Enide最新版本“ Enide IDE 2014”。

There is another solution with Eclipse IDE is Nodeclipse. Nodeclipse is a set of Eclipse plug-ins for programming in JavaScript, CoffeeScript with Node JS Platform.

Eclipse IDE还有另一个解决方案是Nodeclipse。 Nodeclipse是一组Eclipse插件,用于使用Node JS Platform在JavaScript,CoffeeScript中进行编程。

Enide IDE 2014 is a super set of Nodeclipse plugins plus some useful plugins like Angular JS Plugin, RestClient Tool, JSON Editor Plugin, MongoDB Shell Plugin, Gradle Plugin etc. So we are going to use “Enide IDE 2014” Eclipse IDE to develop our Node JS Examples.

Enide IDE 2014是Nodeclipse插件的超级集合,再加上一些有用的插件,例如Angular JS插件,RestClient工具,JSON编辑器插件,MongoDB Shell插件,Gradle插件等。因此,我们将使用“ Enide IDE 2014” Eclipse IDE来开发我们的节点JS示例。

If you are Java Developer, I guess you are already familiar with or used Eclipse IDE in your projects.

如果您是Java Developer,我想您已经在项目中熟悉或使用了Eclipse IDE。

Enide Studio 2014 IDE设置 (Enide Studio 2014 IDE Setup)

Open your Eclipse IDE and click on “Eclipse Marketplace” from “Help” menu.

打开您的Eclipse IDE,然后从“帮助”菜单中单击“ Eclipse Marketplace”。

It opens Eclipse Marketplace as shown in below image.

它将打开Eclipse Marketplace,如下图所示。

Type “enide” in “Find” text box and click on “Go” button. It searches for all available Eclipse software plugins with this name and displays as shown below:

在“查找”文本框中输入“ enide”,然后单击“执行”按钮。 它使用该名称搜索所有可用的Eclipse软件插件,并显示如下:

Enide-Marketplace

It shows “Enide Studio 2014” at first place. Click on “Install” button to install it.


它首先显示了“ Enide Studio 2014”。 点击“安装”按钮进行安装。

Accept licence and click on “Finish” Button to start installation. Once installation is over, please restart your Eclipse IDE to see these updates. Right click on “Explorer” and select “New” menu option. Now you can see some Node JS Option like “Node JS Project” etc. These are installed as part of Enide Studio installation.

接受许可证,然后单击“完成”按钮开始安装。 安装结束后,请重新启动Eclipse IDE以查看这些更新。 右键单击“资源管理器”,然后选择“新建”菜单选项。 现在,您可以看到一些Node JS Option,例如“ Node JS Project”等。这些作为Enide Studio安装的一部分进行安装。

When we open “New” wizard, we can see “Nodeclipse” option as shown below.

当我们打开“新建”向导时,我们可以看到“ Nodeclipse”选项,如下所示。

If we see those options that mean Enide Studio 2014 installation is done successfully.

如果我们看到这些选项,则表明Enide Studio 2014安装已成功完成。

If we install Enide Studio 2014 plugin after installing Node JS Base Platform, then this plugin will pick-up all Node JS Platform settings as shown below.

如果我们在安装Node JS Base Platform之后安装Enide Studio 2014插件,则此插件将提取所有Node JS Platform设置,如下所示。

Select “Preferences” option from “Window” menu.

从“窗口”菜单中选择“首选项”选项。

If you install Node JS Platform after this step, please check and set any missing properties in this Preferences wizard.

如果在此步骤之后安装Node JS Platform,请在“首选项”向导中检查并设置所有缺少的属性。

使用Enide Studio Node IDE开发Node JS项目 (Develop Node JS Project with Enide Studio Node IDE)

Create new Node JS Project by selecting “New >> Other…” from “File” menu.

通过从“文件”菜单中选择“新建>>其他…”来创建新的Node JS项目。

Select Node.js Project from “New” wizard. Click on “Next” button.

从“新建”向导中选择Node.js项目。 点击“下一步”按钮。

Provide new project name as “sample” and also select “Template to use” as “Hello World”.

提供新的项目名称作为“样本”,并选择“要使用的模板”作为“ Hello World”。

Click on “Finish” button. It creates new Node JS Project “sample” and also download libraries.

点击“完成”按钮。 它创建了新的Node JS Project“示例”,还下载了库。

It automatically changes to “Node” Eclipse Perspective as shown below.

它将自动更改为“ Node” Eclipse Perspective,如下所示。

Create a JavaScript file sample.js as shown below by right click on “sample” Node JS Project and select “New” >> “JavaScript file”.

Node.js-New-JS-File

右键单击“示例” Node JS项目,然后选择“新建” >>“ JavaScript文件”,创建一个JavaScript文件sample.js,如下所示。

Provide JavaScript file name and click on Finish button.

提供JavaScript文件名,然后单击“完成”按钮。

Provide some JavaScript code as shown below.

提供一些JavaScript代码,如下所示。

从Node IDE执行Node JS项目 (Execute Node JS Project from Node IDE)

Execute sample.js file from Enide Studio IDE. Select and Right Click on sample.js file. Select “Run As” >> “Node Application” option.

从Enide Studio IDE执行sample.js文件。 选择并右键单击sample.js文件。 选择“运行方式” >>“节点应用程序”选项。

Observe the output at IDE Console.

在IDE控制台上观察输出。

Output: Hello JournalDEV Users!

输出 :您好JournalDEV用户!

Now we have some idea about how to use Enide Studio IDE to develop and run Node JS Applications with simple Java Script file.

现在,我们对如何使用Enide Studio IDE通过简单的Java Script文件开发和运行Node JS应用程序有了一些想法。

We will discuss how to develop Node JS full-fledged application with Angular JS, Express JS, Mongo DB, RESTful WebServices etc in coming posts.

在接下来的文章中,我们将讨论如何使用Angular JS,Express JS,Mongo DB,RESTful WebServices等开发Node JS完整应用程序。

翻译自: https://www.journaldev.com/7527/node-js-basic-examples-with-node-cli-and-node-ide

mac node repl

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值