Nodejs in Visual Studio Code 10.IISNode

Source: Internet
Author: User
Tags node inspector

1. Start

Nodejs in Visual Studio Code 08.iis:http://www.cnblogs.com/mengkzhaoyun/p/5410185.html

Refer to this article to deploy a iisnode example

2. Deploying the node. JS Express Framework sample program in Iisnode

    • Create an Express sample program
$ cd D:\Libraries\Documents\Visual Studio code$ express myapp  Create:myappcreate:myapp/package.json  ... Install dependencies:> CD MyApp && npm installrun the app:> SET debug=myapp:* & npm Start

    • Create a MyApp directory in IIS to publish this node program
      • Application Pools: DefaultAppPool (IIS default,. Net integration)

    • Create a Web. config file to the MyApp directory
      • Note that the startup program for Node Express is the bin/www file
<configuration>  <system.webServer>    <!--bin/www is the Express sample default startup program--    
    • The 404 error will appear when you open address http://localhost/myapp/in the browser
      • The reason is that the bin directory is the default output directory and does not allow module calls by default
HTTP error 404.8-not found the request filtering module is configured to reject the path in the URL that contains the Hiddensegment section.
    • In the MyApp directory, create a new index.js to try to resolve this issue

Cut the bin/www code and delete the bin/www, and modify the portal in Web. config to Index.js

<configuration>  <system.webServer>    <!--Index.js is the start-up program for MyApp--    
    • Browse http://localhost/myapp/at this time, a run-time error occurs
      • This run-time error indicates that node in the execution of the Index.js process error, is a relative address written wrong problem,node finally executed, not easy ah, probably because I will bin/www hard copy come over to forget to fix the relative directory.
Iisnode encountered an error when processing the request.  Hresult:0x2http status:500http substatus:1002http reason:internal Server erroryou is receiving this HTTP response Because system.webserver/iisnode/@devErrorsEnabled configuration setting is ' true '. In addition to the log of stdout and stderr of the Node.exe process, consider using debugging and ETW traces to further di Agnose the problem. The last 64k of the output generated by the Node.exe process to stderr are shown below:application have thrown an uncaught E Xception and is terminated:Error:Cannot find module '. /app ' at Function.module._resolvefilename (module.js:325:15) @ function.module._load (module.js:276:25) at Modul E.require (MODULE.JS:353:17) at require (internal/module.js:12:17) at object.<anonymous> (D:\Libraries\Documen Ts\visual Studio code\myapp\index.js:7:11) at Module._compile (module.js:409:26) at object.module._extensions. JS (module.js:416:10) at Module.load (module.js:343:32) at Function.module._load (Module.js:300:12) at Module.require (module.js:353:17) 
    • Modify Index.js
      • .. /app changed to./app a little bit less, you see?
var app = require ('./app '); var debug = require (' Debug ') (' myapp:server '); var http = require (' http ');
    • re-visit, error cannot find module ' Serve-favicon ' , careless forgot npm install ...
    • Execute cmd command NPM install dependency package for MyApp
    • Re-visit webpage http://localhost/myapp/, 404 Not Found appears
      • Virtual path error, need to modify virtual path in App.js
Not found404error:not Found @ D:\Libraries\Documents\Visual Studio code\myapp\app.js:30:13 at Layer.handle [as Han Dle_request] (D:\Libraries\Documents\Visual Studio code\myapp\node_modules\express\lib\router\layer.js:95:5) at Trim_prefix (D:\Libraries\Documents\Visual Studio code\myapp\node_modules\express\lib\router\index.js:312:13) at D : \libraries\documents\visual Studio Code\myapp\node_modules\express\lib\router\index.js:280:7 at Function.process_ params (D:\Libraries\Documents\Visual Studio code\myapp\node_modules\express\lib\router\index.js:330:12) at Next (D : \libraries\documents\visual Studio code\myapp\node_modules\express\lib\router\index.js:271:10) at D:\Libraries\ Documents\Visual Studio code\myapp\node_modules\express\lib\router\index.js:618:15 at Next (D:\Libraries\Documents\ Visual Studio code\myapp\node_modules\express\lib\router\index.js:256:14) at Function.handle (D:\Libraries\ Documents\Visual Studio code\myapp\node_modules\express\lib\router\iNdex.js:176:3) at router (D:\Libraries\Documents\Visual Studio code\myapp\node_modules\express\lib\router\index.js : 46:12)
    • Modify App.js, Note that the release path is MyApp, finally see Welcome to express not easy ah, don't forget to change the path of the public directory
App.use ('/myapp ', Express.static (Path.join (__dirname, ' public ')); App.use ('/myapp ', routes); App.use ('/myapp/users ', users);
    • To modify the Views/layout.jade, note that there is a relative path to the CSS, minus the front slash
DOCTYPE htmlhtml  head    title= title    link (rel= ' stylesheet ', href= ' stylesheets/style.css ')  body    block Content

    • Open Http://localhost/myapp/index.js/debug remote debugging in Chrome, an error, or a pattern.
      • It seems that this index.js/debug connection was executed by the app ...
      • So far, all errors have been completely impossible to debug, relying on my (wo) (shi) Feng (CAI) Rich (DE)

    • The cause of the above error is urlrewriter configuration

All the execution requests under the MyApp are given to Index.js to execute, obviously myapp/index.js/debug this address should not give index.js to execute.

Modify the URL rewriter section in Web. config to set index.js/debug this address to a mismatch negate= "true".

<configuration>  <system.webServer>
<!--Index.js is the start-up program of MyApp--

    • Finally see Node Inspector, enter Http://localhost/myapp/users,Node in the browser inspector will capture this processing

3. Summary

Iisnode a variety of diao, support after the release of cross-platform remote debugging, if the release process encountered problems how to do it, Iisnode released 5 years (currently 0.2.* version), should have accumulated a lot of issues, an article turned to see, or to ask the author to solve it.

Sample code, go to:https://github.com/Mengkzhaoyun/nodepractise

04.iisnode&myapp

Nodejs in Visual Studio Code 10.IISNode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.