当前位置: 首页 > 编程日记 > 正文

[转]Getting Start With Node.JS Tools For Visual Studio

本文转自:http://www.c-sharpcorner.com/UploadFile/g_arora/getting-started-with-node-js-tools-for-visual-studio/

Table of contents 1. Introduction 2. What Node.JS is 3. How to install Node.JS 4. Let's Start by Creation of a Simple App

  • Pre-requites
  • Create Skeleton/Empty ASP.Net project
  • Discussing Node.JS templates
    • From Existing Node.JS code

      • Blanks Node.JS Console Application
        1. Folder Structure
        2. Install/Update Node dependencies
      • Blanks Node.JS Web Application

        1. Folder structure
        2. Visual Studio Intellisence Experience
      • Basic Node.JS Express 3 Application
        1. Folder Structure
        2. Running the application
        3. Analyzing app.JS
        4. Debugging App
      • Node.JS Interactive Window
      • Diagnostic Info
      • Discussing features of Node.JS tools for Visual Studio
        1. Visual Studio IDE Flavor with Node.JS tools
        2. Debugging experience
        3. TypeScript support

5. Conclusion
Introduction

On November 24, 2014 there was a release of powerful tools, Node.JS, for Visual Studio. This tool has the latest great features that enable the powerful Node.JS for your Visual Studio.
Today, March 25, 2015 there is an announcement for general availability of Node.js Tools 1.0 for  Visual Studio. All the example and demo code is written in new syntax and abreviations.
To know more about this announcement, please read: http://www.c-sharpcorner.com/news/4429/node-js-tools-1-0-for-visual-studio-announced.aspx

What Node.JS is Node.JS is a tool for Visual Studio that enables the Node.JS working experience with your Visual Studio.
How to install Node.JS The following guide provides a procedure for installing Node.JS tools for Visual Studio. Please note that in this article we are using Visual Studio 2013 Update 4.

  • Go to Node.JS Tools for Visual Studio
    Node JS Figure 1: node.JS tools for Visual Studio
  • Choose recommended downloads
    installation instructions for nodejs Figure 2: installation instructions for node.JS
  • Follow the instructions and it will install the great tools of Node.JS
    Getting installation completed for nodejs Figure 3: Getting installation completed for node.JS

Let's Start Creation of a Simple App
In this article we will use builtin templates to start building simple apps.
Pre-requites To implement and play with the source code, one should have:

  • Visual Studio 2013 express or later
  • Node.JS Tools for Visual Studio
  • Basic knowledge of Node.JS

Create Skeleton/Empty ASP.Net project

  • Open Visual Studio 2013.
  • Select "File" -> "New" -> "Project..." (or enter Ctrl + Shift + N).
  • Under Installed Templates Select JavaScript -> Node.JS.
    New Project Templates Figure 4: New Project Templates

Discussing Node.JS templates
Let's discuss the available templates, these may increase or decrease depending on your custom installation or add-ons.
From Existing Node.JS code You can use this template if you have already created a Node.JS app and now want to taste the flavor of Visual Studio. No need to do any special things, just choose this template and select the path of your existing Node.JS app and you're all done (y).
Blanks Node.JS Console Application This template creates an empty application, just a skeleton for you. Let's provide a hands-on experience with this template to learn more about it.
Selecting a new project template Figure 5: Selecting a new project template
Have a look at the preceding image and note that:

  • Do not select "Create directory for solution".
  • Do not select Add to source control (unless you want to).

Click Ok to get the application routed.
The first file you will see has the following code:
console log
Just run the application (F5), you wil see your console window appears and disappears so quickly and you cannot see the expected output.
Let's re-write the code above (so we can hold our console window for a moment) as in the following:
set timeout
In the preceding snippet just add the time our function to hold our window for 3000 ms.
That is a great thing, now we can see the output as in the following:
Console App output Figure 6: Console App output
Folder Structure Let's have a look into the folder structure:
console app folder structure Figure 7: Typical node.JS console app folder structure
Here you can see that our console app consists of:

  • npm: all Node.JS dependencies
  • app.JS: our simple node.JS stuff a JavaScript file
  • package.json: all about configuration, project details, version and author details and so on.
    a typical package json file Figure 8: a typical package.json file
  • README.md: a normal readme file

Install/Update Node dependencies Just right-click on the project from the Solution Explorer and click on the Open Command Prompt.
Open command prompt from Visual Studio Figure 9: Open the command prompt from Visual Studio
In the command prompt type "npm install".
Installing node js project dependencies Figure 10: Installing node.JS project dependencies
It will install all the dependencies required for the project.
Alternatively expand the "npm" node from the Solution Explorer and right-click the project and choose Update Install Package(s), it will update all the packages with the latest.
Also, you can do it by opening a npm install window above the option (Ctrl K,P):
Installing new npm package Figure 11: Installing new npm package
Blanks Node.JS Web Application Now, let's try another node.JS template. Close the existing solution or just add a newer one and choose Blank Node.js Web Application template.
Getting started with Node js blank web template Figure 12: Getting started with Node.JS blank web template
The first file will open after the preceding action:
typical server js file Figure 13: typical server.JS file
Run application (hit F5).
You will see two things happen:

  1. A command window invoked; this is saying that the node server is running on port 5858
    blank web app
  2. A web browser invoked with a output from the server.JS file (this is a default project file).
    hello word

Folder structure
You can find a folder structure similar to the one in the node.JS Blank console app.
Typical folder structure of nodejs Figure 14: Typical folder structure of node.JS blank web app Visual Studio Intellisence Experience Let's try with writing something in the server.JS file, you will see that you get Visual Studio's typical intellisence.
Visual Studio Intellisence Experience
So, you can get the flavor of all Visual Studio things the same as if you were getting when working with other languages like C# / ASP.NET and so on.
Basic Node.JS Express 3 Application This template provides the ability to create a basic Node.JS app with Express 3 packages
Node js Express 3 application Figure 15: Node.JS Express 3 application
During the preceding operation you can see the following dialog.
nodejs tools
So, your project has all the dependencies defined in the Package.json file.
If you clicked yes then you will definitely see the following message in the Visual Studio status bar.
readdrip
Which tells us about the installing package. The amazing thing is this process happens in the background. That means you can work with your task at the same time.
If you clicked "No", don't worry, you can still install the packages, just open the Command Prompt by right-clicking the project name from the Solution Explorer and just type "npm install" and hit Enter.
npm install
Folder Structure Have a look into the following folder structure:
ExpressApp
In the preceding you can see various folders containing different files. You can see views, routes, public and so on. In this article we are not going to discuss everything in details, we will do this in a future Node.JS series of articles.
Running the application Run the application (hit F5) and you will see:

  • Command window
    Command window
  • Web browser
    Web browser

Analyzing app.JS
Let's get the code lines that were added by the default template.
Analyzing app
The code above tells the Node.JS that these modules are required to run this app.
app variable
It will initialize our express.JS function.
development
This will only happen in a development environment.
development environment
the first line tells the main/home page and second will provide is the response of our resource.
response of our resource
Debugging App Put a breakpoint somewhere in your app.JS file.
Debugging App
Run the app (hit F5), see when it hits the breakpoint.
The great thing is that you can see the breakpoints in the Visual Studio Breakpoints window as in the following:
breakpoint
Here is the Call Stack window containing everything.
Locals windows
You can find the local variables and functions in your Locals windows.
functions in your Locals windows
Isn't it an imagine tool?
There are more templates that we will not discuss here, we will discuss and create a separate application using these templates in our future Node.JS  article series. Until then enjoy the flavor of this new Node.JS tools for Visual Studio.
Node.JS Interactive Window You can find this window similar to the Visual Studio Command Window:
Go to Tools -> Node.JS Tool -> Interactive Window. Alternatively press Ctrl+K,N.
Nodejs interactive window Figure 16: Node.JS interactive window
In this window you can play with all the Node.js commands, this is one of the most powerful windows I have ever found. If you have some confusion then just type .help and you will get a list of commands:
a list of available commands
Let's play with a few of commands.

Figure 17: a list of available commands
Let's play with a few of commands.
Did you remember that we created a console app?
created a console app
Here we can get the similar output. Did you notice "undefined"? What was that?
Defining a function in Nodejs Figure 18: Defining a function in Node.JS Interactive Window
In the preceding, we just defined a function "letsTryThis". This is a simple JavaScript function. You can think how to run it from within the same window, let's try and call that function as in the following:
Executing defined function Figure 19: Executing defined function
Wow, it works! One more great thing you can get is the History by pressing the up or down error keys. So, enjoy the power of the Node.js Interactive Window (y).
Diagnostic Info You can get all the info about your current node.JS app (please note that the info depends upon your current node.JS app). Go to Tools -> Node.js Tools ->Diagnostic Info.
Diagnostic report of a typical nodejs Figure 20: Diagnostic report of a typical node.JS console app
a typical mvc app with nodejs Figure 21: a typical MVC app with node.JS
Discussing features of Node.JS tools for Visual Studio Let's discuss a few of the great features of Node.JS tools for Visual Studio. Visual Studio – IDE Flavor with Node.JS tools
With the installation of this tool we can get all the flavor of Visual Studio IDE, we can see:

  • Intellisence
  • AutoComplete
  • Signature help

Debugging experience
With this great tool we can put a breakpoint and DEBUG the application similar to other applications that run in Visual Studio.
TypeScript support
Node.JS tools for Visual Studio comes with the support of TypeScript, you can write your things using TypeScript.
In the preceding, we have almost tried to attempt all the features with valid examples. In future sessions we will create an entire application following great patterns.
Conclusion
Finally we will get the great thing Node.js tools for Visual Studio, it provides all the flavour of Visual Studio to develop Node.JS applications. This tool has many great features, it provides great Node.JS templates.

Gaurav Kumar Arora
Gaurav Kumar Arora

Gaurav is a Microsoft Technology Specialist professional. He has awarded lifetime membership from Computer Society of India (CSI). He is having more than 14yrs of experience in the industry.  Currently, he is workin... Read more

Personal Blog: http://gaurav-arora.com

转载于:https://www.cnblogs.com/freeliver54/p/4980136.html

相关文章:

Java学习总结:16

匿名内部类 匿名内部类指的是没有名字的内部类,其必须在抽象类或接口基础上才可以定义。 例:采用匿名内部类简化类的定义 interface Message{ //定义接口public void print(); } public class Test1_1_4_9 {public static void main(String args[]){fu…

Java 多线程概述

多线程技术概述 1.线程与进程 进程:内存中运行的应用程序,每个进程都拥有一个独立的内存空间。线程:是进程中的一个执行路径,共享一个内存空间,线程之间可以自由切换、并发执行,一个进程最少有一个线程&am…

nginx图片过滤处理模块http_image_filter_module安装配置笔记

http_image_filter_module是nginx提供的集成图片处理模块,支持nginx-0.7.54以后的版本,在网站访问量不是很高磁盘有限不想生成多余的图片文件的前提下可,就可以用它实时缩放图片,旋转图片,验证图片有效性以及获取图片宽…

Centos7 安装 telnet 服务

准备写一个 django-webtelnet(运维管理系统集成后管理网络设备),但是手边没有现成的网络设备资源可以测试,那就研究下 Centos7 下安装 telnet-server 吧。 安装 yum -y install xinetd telnet telnet-server telnet-server 是以 x…

Zbrush制作手榴弹案例讲解学习教程

Sculpting In Zbrush- Project Grenade! MP4 |视频:h264,1280720 |音频:AAC,44.1 KHz,2 Ch 语言:英语中英文字幕(根据原英文字幕机译更准确) |时长:44节课(11h 43m) |大小解压后:11 GB 含课程素材 云桥网络…

Winform控件缩写

控件名称 缩写 Buttom按钮 Btn CheckBox复选框 Chk ColumnHeader视图列表头 Col ComboBox组合框 Cbo ContextMenu快捷菜单 Ctm DataGrid数据网格控件 Dg DataGridView数据网格视图控件 Dgv DteTimePicker时间输入框 Dtp DomainUpDown数值框 Dud Form窗体 …

Java习题:1

假设类X是类Y的父类,下列声明对象x的语句中不正确的是( )。 A.X xnew X(); B.X xnew Y(); C.Y xnew Y(); D.Y xnew X(); 答案:D 向下转型操作本身是有前提条件的,必须发生向上转型后才可以发生向下转型。 各个选项的代码实现: …

2022-2028年中国廉价航空行业深度调研及投资前景预测报告

【报告类型】产业研究 【报告价格】4500起 【出版时间】即时更新(交付时间约3个工作日) 【发布机构】智研瞻产业研究院 【报告格式】PDF版 本报告介绍了中国廉价航空行业市场行业相关概述、中国廉价航空行业市场行业运行环境、分析了中国廉价航空行…

【SSRS】入门篇(二) -- 建立数据源

原文:【SSRS】入门篇(二) -- 建立数据源通过 【SSRS】入门篇(一) -- 创建SSRS项目 这篇,我们建立了一个SSRS项目; 接下来,我们以 AdventureWorks2012 示例数据库,讲下如何建立数据源;(AdventureWorks2012 下载) 1、解决…

k8s相关的面试题

k8s相关的面试题 https://blog.csdn.net/huakai_sun/article/details/82378856 posted on 2019-07-30 20:33 竹径风声 阅读(...) 评论(...) 编辑 收藏 转载于:https://www.cnblogs.com/girl1314/p/11272568.html

CG游戏道具全流程制作视频教程 Artstation – Stylized Game Asset

CG游戏道具全流程制作视频教程 Artstation – Stylized Game Asset 时长:9h 30m 含项目文件 1920X1080 MP4 语言:英语机译中文字幕 教程大小:4G 标题:Artstation–风格化游戏资产 云桥网络 获qu 教程 信息: 内容&a…

Java学习总结:17

包及访问控制权限 包的定义 在Java中使用package关键字来定义包,此语句必须写在xxx.java文件的首行。 例:定义包 package com.study.Demo; //定义程序所在包,此语句必须放在首行public class Hello {public static void main(String args[…

常用的网络配置命令 ifconfig 所在的包

通过rpm的数据库反查 ifconfig这个可执行文件的提供者,得出这个文件属于一个叫 net-tools 的包 转载于:https://www.cnblogs.com/vanwoos/p/4987375.html

Sentinel 高可用流量管理框架

Sentinel 是面向分布式服务架构的高可用流量防护组件,主要以流量为切入点,从限流、流量整形、熔断降级、系统负载保护、热点防护等多个维度来帮助开发者保障微服务的稳定性。 Sentinel 具有以下特性: 丰富的应用场景:Sentinel 承接了阿里巴巴近 10 年的双十一大促流量的核心…

'libxml/tree.h' file not found

本文转载至 http://www.cnblogs.com/hanjun/p/3711173.html 看看Header Search Paths 为 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/usr/include/libxml2 看看Base SDK 为 ios 6.1 于是把Header Search Paths 该…

Spring Cloud 微服务实战笔记

Spring Cloud 微服务实战笔记 微服务知识 传统开发所有业务逻辑都在一个应用中, 开发,测试,部署随着需求增加会不断为单个项目增加不同业务模块;前端展现也不局限于html视图模板的形式,后端向前端支持需要更多的接口模块。 随着需求增多&…

UE商城资源 Kitsune狐狸女孩

Unreal Engine虚幻游戏引擎素材资源 Unreal Engine Marketplace –Kitsune 4.26狐狸女孩 大小解压后:569M 可爱的Kitsune的3D模型。装配到史诗骷髅。完全模块化,包括无衣服的身体。包含不同的发型。通过材质实例轻松改变颜色。包含与Live Link Face应用程…

Java学习总结:18

认识异常 异常是程序中导致程序中断的一种指令流。 例:产生异常 package com.study.Demo;public class Test1 {public static void main(String args[]){System.out.println("1.除法计算开始");System.out.println("2.除法计算:"(…

java从字符串中提取数字

1、做一下操作时会一般会用到提取数字操纵: a、列表中有翻页,当新添加的数据不是放在第一条或者最后一条时,需要翻页并循环找到对应的那条数据 b、当新添加的数据放在第一条或者最后一条时,则不需要翻页,只需要直接进入…

2022-2028年中国联合办公行业深度调研及投资前景预测报告

【报告类型】产业研究 【报告价格】4500起 【出版时间】即时更新(交付时间约3个工作日) 【发布机构】智研瞻产业研究院 【报告格式】PDF版 本报告介绍了中国联合办公行行业市场行业相关概述、中国联合办公行行业市场行业运行环境、分析了中国联合办…

iBatis自动生成的主键 (Oracle,MS Sql Server,MySQL)【转】

iBatis的sqlMap配置文件的selectKey元素有个type属性&#xff0c;可以指定pre或者post表示前生成(pre)还是后生成(post)。 Oracle设置 Xml代码 <!-- Oracle SEQUENCE --> <insert id"insertProduct-ORACLE" parameterClass"com.domain.Product&quo…

微信小程序----调用用户信息

在对应的文件夹里面的js里面添加代码&#xff0c;例如&#xff1a;index.js 代码开始/// onLoad: function () {var that this// 查看是否授权wx.getSetting({success(res) {if (res.authSetting[scope.userInfo]) {// 已经授权&#xff0c;可以直接调用 getUserInfo 获取头像…

在Blender中创建真实的汽车CGI视觉动画效果

Blender VFX Tutorial Rig & Animate a Realistic Car in Real 大小&#xff1a;1.18G 时长1h 包含项目文件 1280X720 MP4 语言&#xff1a;英语中英文字幕&#xff08;根据原英文字幕机译更准确&#xff09; Blender VFX教程绑定&动画真实的汽车 云桥网络 平台获取教程…

Java学习总结:19

throws关键字 throws关键字主要在方法定义上使用&#xff0c;表示此方法中不进行异常的处理&#xff0c;而是交给被调用处处理。 例&#xff1a;使用throws package com.study.Demo;class MyMath{public static int div(int x,int y)throws Exception{ //此方法不处理异常re…

C语言访问网页

一、理论 http://www.zixue7.com/thread-3860-1-1.html转载于:https://www.cnblogs.com/274914765qq/p/4996433.html

禅道Docker安装包发布

禅道Docker安装包发布 大家好, 禅道Docker安装包发布。 一、下载地址 禅道开源版: /dl/zentao/docker/docker_zentao.zip 备用下载地址:https://download.csdn.net/download/u013490585/16271485 数据库用户名: root,默认密码: 123456。运行时,可以设置 MYSQL_ROO…

获取指定日期之间的各个周和月

2019独角兽企业重金招聘Python工程师标准>>> 日志格式化类 Date.class.php <?php class Datefmt{function __construct() {}/*** 根据指定日期获取所在周的起始时间和结束时间*/public function get_weekinfo_by_date($date) {$idx strftime("%u", s…

nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping

今天mybatis报了个错误 org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{propertyInfoId, modeIN, javaTypeclass java.lang.Long, jdbcTypenull, numericSca…

Revit和Unreal Engine真实的建筑可视化视频教程

Revit和Unreal Engine真实的建筑可视化视频教程 Lynda – Revit and Unreal Engine: Real-Life Architectural Visualizations Lynda–Revit和Unreal Engine&#xff1a;真实的建筑可视化 时长 3小时 25分 | 1.15 GB |含项目练习文件|使用的软件&#xff1a;Revit&#xff0c…

Java学习总结:20

可变参数 语法形式&#xff1a; [public | protected | private][static][final][abstract] 返回值类型 方法名称(参数类型...变量){[return[返回值];] }例&#xff1a;使用可变参数定义方法 package com.study.Demo;public class Test6 {public static void main(String ar…