Visual Studio Code, Debugging Node - How can I hit this 'Unverified Breakpoint'? - javascript

I'm just starting both with node and VSCode (and to some extent, javascript) so this may be a schoolboy error.
There's just one javascript file, writefile.js :
var fs = require('fs');
process.stdin.on('data', function (text) {
fs.writeFileSync("test.txt", text, 'utf8');
console.log("The file was saved.");
process.exit();
});
console.log('what do you want to write?');
Which works fine with no debugger attached.
Now I'm trying to debug - to keep the scenario simple, I'm just manually launching node in the console with
node --debug-brk writefile.js
If I put a breakpoint on the fs.writeFileSync line, when I attach the debugger in Visual Studio Code, I get a message that it's an 'Unverified Breakpoint':
The other breakpoints are hit fine. I'm expecting all depicted breakpoints be expected to be hit before the writeFileSync one, which should only be hit after the user input at the console.
I tried using the -nolazy option when launching node - but the breakpoint is still showing as unverified, and I also get a long pause while 'Evented IO for v8 javascript' ramps up in memory usage...
What am I doing wrong?

Problem was solved by upgrading node to 4.4.3 - I was on a v0.11 version from 2014.
Would still be interested in why this doesn't work in older versions.

Related

Aw, snap error in chrome while insert value into web sql using executeSql

I am creating a sqlite editor for android application, it is execute correctly still yesterday and finally just I tried to backup the chrome websql db so just copy the files from the following path "C:\Users\merbin.SERVER\AppData\Local\Google\Chrome\User Data\Profile 1\databases" and "C:\Users\merbin.SERVER\AppData\Local\Google\Chrome\User Data\System Profile\databases". Today I got the Aw, snap error on chrome, I debug the error and found, the error occur when I trying to create a table or inserting data into the database. But select query is execute perfectly. Some code examples are
query="insert into tbl(Type) values('Test')";
insert_query(query,insert_success,insert_fail);
function insert_query(query,succ_fun,fail_fun)
{
db.transaction(function(tx,result)
{
tx.executeSql(query, [],
function(tx,result)
{
eval(succ_fun)(result)
});
},eval(fail_fun));
}
function insert_success(result)
{
debugger;
$("#ex_area").empty();
$("#ex_area").append(result.rowsAffected+" Row(s) Affected.<br> Last Inserted ID is "+result.insertId);
alert("Insert Success");
return false;
}
function insert_fail(result)
{
debugger;
$("#ex_area").empty();
$("#ex_area").append("<span class='error'>"+result.message+"<br> Code : "+result.code+"</span>");
}
After that "eval(succ_fun)(result)" line I getting the Aw, snap error. screenshot is shown below.
image 1 Error on the Next Line Execution Screenshot
image 2 From previous line I am getting this error
Note : I think after update the chrome I have this problem.
I have solve this problem running the code through localserver. First the chrome allow to access the websql without using any server, but recent update chrome has change that rule. So must need any local server like xampp,wamp,IIS or etc...
by running the code through localserver: your JavaScript hosted through local server or the database or both
Create a new Google Chrome shortcut on your desktop.
Right click it, then click properties.
Add -allow-file-access-from-files to the end of the Target.
The end of the target should look like this:
\chrome.exe" -allow-file-access-from-files
Go into Task Manager.
Click Details.
End every single chrome.exe which is running.
Open up Google Chrome using the new shortcut you created.
Open up your website which uses WebSQL.
This worked for me.
Warning:
-allow-file-access-from-files lets Google Chrome have access to all of the files on your computer. ONLY, ONLY use this shortcut for developing. Do not browser the web, especially to untrusted websites, while you have this feature activated.
To deactivate it:
Go into task manager and end all chrome.exe's then open up chrome with a normal shortcut.

VS2015 error "Application is not currently attached to a script debug target that supports script diagnostics"

I created JS & HTML5 Blank App with Visual Studio 2015. When running it in VS debugger in "Local Machine" mode, I get the following error message:
Application is not currently attached to a script debug target that
supports script diagnostics
Just ignoring the error is not workable as at least breakpoints and console.log("text") do not work.
I'm having default options in VS.
I am running normal Win10, with automatic updates on.
Reinstallation of VS2015 did not solve the issue.
This worked for me although I was doing something slightly different. I got the same error message using IE 11 accessing a HTML file from my local file system (was mucking around with HTML). Seems IE developer tools don't much like this mode of operation (why?!). Here's my story...
File on my local windows laptop:
c:\temp\test.html
Can be opened in these browsers:
URL: file:///C:/Temp/test.html (in chrome)
URL: C:\Temp\test.html (in IE 11)
In Chrome tools commands in the console can be run no problem e.g.
console.log("hi");
In IE developer tools this fails with the message cited by the op.
I had a reverse proxy installed on my laptop (nginx) so tried serving the file up via HTTP and this fixed the issue with IE. Here's how I would access the file via HTTP via the proxy:
http://localhost:9092/temp/test.html
For reference here's my nginx.conf (but any other proxy would I expect work fine)...
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
server {
listen 9092;
server_name localhost;
location /temp {
alias "C:/temp/";
}
}
}
In my case (VS 2017 not 2015), the option shown below had somehow become unticked (I'm blaming an update). Before ticking this I was getting the same error as the OP; after ticking it, all is well again.
NB I'm debugging the Javascript within a WebBrowser control hosted in a Winform.
I finally got this solved with the help of Jack-Zhai in msdn forum. So, the summary of my journey:-
Problem:
- Running JS UWP blank app in debug mode & local machine w default settings in VS2015 generates a warning "Application is not currently attached to a script debug target that supports script diagnostics" into JavaScript console. Breakpoints do not work, adding console.log("here") does not write anything to console
Solution trial 1:
- changing and playing with VS2015 settings; the problem still exists
Solution trial 2:
- reinstalling VS2015; the problem still exists
Solution trial 3:
- reinstalling Windows10 - all applications deleted but user data not
- installing VS2015
=> Problem solved; debugging blank app works, and console.log("test") works

node does not output using console log

I fairly new to nodejs and I put the following code in some module,
module.exports = function (app) {
app.get('/aa', function(req, res) {
console.log("test");
debugger;
res.send('file updated');
...
the application is working and I see in the browser "file updated"
but I've two problems:
why don't I see "test" in the console?
I set up a debugger (using WebStorm 10) and it does not stop, what am I missing here?
I try also to run the debugger in Webstorm and click on debug and I see in the terminal Debugger listening on port 55236 but when I change the port in the browser nothing happen, any idea?
Node runs server side, so any console.log statements will appear in the the console you ran your script from. You won't see any debug statements in the browser except those from client js code. The reason you see file updated is because you sent that string as a response to your browser, and its simply spitting back the response it got.
Same thing with the debugger. If you are using your browser's debugger, it will only affect client js code, NOT your server code. Not too familiar with WebStorm, but they have instructions for debugging Node.js specific code here

crash dumps missing nodewebkit

I'm developing an application (on Windows now but I'd like to have a mac version as well) using angularjs and node webkit.
It happens that my application crashes but I don't know why. So I thought I should check the dump file generated as precised here : https://github.com/rogerwang/node-webkit/wiki/Crash-dump
So here is my code :
// Load native UI library
var ngui = require('nw.gui');
ngui.App.setCrashDumpDir("logs");
// Get the current window
var nwin = ngui.Window.get();
// show devtools to debug
nwin.showDevTools();
onload = function() {
nwin.show();
nwin.maximize();
}
ngui.App.crashBrowser();
I've put the last line to find a crash report but I'm unable to find any in the logs folder of my application.
Why ?
Thank you
I did some digging in the source and found the reason. It appears that setCrashDumpDir has been disabled in 0.12 for whatever reason.
In breakpad_win.cc, SetSetCrashDumpPath should have been called from app.cc (nw.app module).
The commit responsible for this was authored by GnorTech and has been disabled since Aug. 29th, 2014.
I'm going to raise a bug report for this.
EDIT:
Looks like a bug report already exists. https://github.com/nwjs/nw.js/issues/3226

How run a windows console for JavaScript

I would like to have a console window (a command line) on Windows 7 which will allow me to play with JavaScript just like a python console.
Update:
It's important to have a file access from within the console (or script run through it).
You can use Node.js's REPL. To do so follow this steps:
Download and Install Node.js.
Call Node.js from the Start Menu / Start Screen or directly node.exe installation path (e.g C:\Program Files\nodejs\node.exe).
Enjoy!
You may want to add the installation path to your PATH enviroment variable for ease of use.
Note: to leave node.js press Ctrl + C twice.
To access the local files, you will need the File System module. This is an example of usage:
var fs = require("fs");
fs.readFile(
"C:\\test.txt",
function(err, data)
{
if (!err)
console.log(data.toString());
}
);
This will output the contents of the file C:\test.txt to the console.
Note: An unhandled exception will cause node.js to "crash".
You can just use the developer tools.
For example, in Chrome, press F12. This will bring up the developer tools. The last option on the menubar is console. This will allow you to create JS variables and functions and to interact with DOM elements on the current page
It's possible thanks to Mozilla Rhino JavaScript Engine.
To create a console window for JS:
1) Download Mozilla Rhino JavaScript Engine binary.
2) Extract: js.jar.
3) Create a script to run the console window (e.g. rihno_console.bat):
java -cp js.jar org.mozilla.javascript.tools.shell.Main
For more information about usage (for instance, and global functions inside this console) visit the Rhino Shell web page.
Just like I informed another user with the same question as yours who was faced with the same need, check out DeskJS (https://deskjs.wordpress.com). It's a portable Windows console application that lets you run pure JavaScript code and even load any existing JS files. It supports even the basic JS popup boxes implemented in browsers. You can save your commands as JS files that can be run on startup or by dragging-and-dropping them on the app. Plus there's so much more to it like you can create a build system for Sublime Text that can run JS files via cmd, it supports themes for customizing the entire console and snippets which let you save short snippets of JavaScript code for later use. Improvements are still being made on the app together with other native APIs being included. Hope this helps you as it did for me.

Categories

Resources