How to configure nodejs on vscode extension on Mac - node.js

i use vscode on Mac for nodejs applications.
I installed the **Mocha Side Bar** module, for help me test my unit tests.
The problem is that vscode doesnt see the 'Nodejs' installation, and each time i try to execute the 'mocha test run', i am getting these errors:
The root of my nodejs installation is on that path: /Users/theodoros.itzaris/.nvm/versions/node/v6.11.5/bin/node
It seems a simple configuration issue, but i m new to both mac & vscode.
And i did not manage to find any tutorial on that.

You can specify an absolute path to your nodejs installation by setting the program attribute in your launch.json:
"program": "/Users/theodoros.itzaris/.nvm/versions/node/v6.11.5/bin/node"
All available launch configuration attributes can be found in this docs.
Update
Here is explained how the extension works and furthermore stated
It will search for the installed Node.js as indicated by environmental variable PATH
Therefore ensure that you have added node.js to your system's PATH variable.

Related

PATH variables empty in electron?

I'm trying to access items in my PATH environment variable from my electron instance, when I run it with npm start while developing it through node.js I get all the expected variables, but when I run the electron application with my resources inside I'm left with only usr/bin
This is how it looks like when I run it from npm:
And this is how it looks when run from the electron mac application precompiled:
Does anyone know why this could be the case? And if I can do anything to reach my normal PATH variables
UPDATE:
After a lot of research I found out that GUI applications ran from finder or docker in Mac OSX use different environment variables compared to if they are ran from the terminal:
This can be edited through plist files, either globally or application specific
You can use fix-path package. Works perfectly!
const fixPath = require('fix-path');
console.log(process.env.PATH);
//=> '/usr/bin'
fixPath();
console.log(process.env.PATH);
//=> '/usr/local/bin:/usr/bin...'

VSCode and starting a project with launch.json

I installed VScode, but when I try to debug it has giving me an error msg.
Can not find runtime 'node' on PATH. Is 'node' installed?
I don't know what to do. I installed node js and what needed in it's instruction
If you have installed nodejs then you can build the project. You are trying to debug so i think you have done installlation step right. If you try to run a starter project then its version maybe higher then your node. In this state you should install last version of the node.
I think your problem is that your path is wrong.
The file path that project's itself and the compiler looking for, should not contain any invalid character, like empty ş, i, ü, etc..
Your project has to read and write permission to that directories.
You should try aboves, your error may be change or if your launch.json is right then it will work out
try to check
run cmd => 'node --version'
if it is installed well, you can check the version.
if you cant check the version, add a environment variable
bascially node.js path is ''C:\Program Files\nodejs\'
Add the path into 'Path' of 'System variable'

node 6.11.3 NODE_EXE not found in IntelliJ

I've updated my project to use node 6.11.3. When I now try to start a npm-script by using the Run-configurations provided from IntelliJ, I always receive the following error:
Error: Failed to replace env in config: ${NODE_EXE}
Important: This error appears only if I start npm from within my project. If I use the windows cmd, the error doesn't appear.
What could possibly have changed between node 6.11.2 and 6.11.3? Because with the prior version, everything worked fine.
A workaround for me is to add the NODE_EXE variable to my run configuration, but In my opinion, that shouldn't be needed, because it worked in 6.11.2 too.
Looks as if you have ${NODE_EXE} variable set in one of your npmrc files (see https://docs.npmjs.com/files/npmrc#files), and it can't be properly expanded for some reason when you run your script in the IDE.
is the issue specific to certain project?
how many npm versions do you have installed? Please check that npm chosen in Node.js Interpreters dialog is the same as you use in cmd shell?
please create an env.js file with console.log(process.env) and try running it via npm ("env" : "node env.js") in both cmd console and WebStorm - what is the result?

Error code: 800A1391 Source: Microsoft JScript runtime error Running Grunt - Module is undefined

New Grunt user here who is using a lot of new tools (npm nodejs) today.
I've got Grunt "installed" and have been able to create a grunt.js file using the init task as described here: http://net.tutsplus.com/tutorials/javascript-ajax/meeting-grunt-the-build-tool-for-javascript/ and here: https://github.com/cowboy/grunt/blob/master/docs/getting_started.md. But whenever I run the "grunt" command I get an error:
Windows Script Host
Script: c:\users\[]\Documents\code\grunt\grunt.js
Line: 2
Char: 1
Error: 'module' is undefined
Code: 800A1391
Source: Microsoft JScript runtime error
As explained in the FAQ, you need to type grunt.cmd instead on Windows because the OS tries to launch grunt.js
Or you can install grunt-cli globally instead. This package will run any version of Grunt if it's been installed locally to your project.
SOLVED !!
So, this problem occur because windows by default associative < *.js > files
with >>
"Microsoft Windows Based Script Host".
grunt need to open by default with (grunt.cmd).
it easy to slove, by change default app (open with..)
Guide :
Go to any javascript file with "js" extension. (any file)
Right-Click(mouse) > Properties > "Opens with:" Change...(button)
Choose Notepad ( or any javascript IDE ).
PROBLEM SOLVED ! :)
good luck
If you're getting a "Microsoft JScript runtime error" that means that node.js isn't even getting invoked; instead Windows Script Host is trying to run your code. That's probably a problem with filetype associations; IIRC Windows defaults to trying to execute a ".js" file with WSH. You may wind up having to create a shortcut to your script, specifying a command line (probably something like "node %1") and a starting directory in order to make sure that it's executed properly.
It would help if you could tell us exactly how you're trying to invoke your code.
it seems that in the latest versions of the grunt modules, you would have to do the following to have it work under windows:
remove any globally installed grunt
npm uninstall -g grunt
install grunt-cli globally
npm install -g grunt-cli
install grunt locally into your project
npm install grunt
installing grunt (v0.4.x) globally does not seem to create the necessary grunt.cmd anymore. it seems that the recommendation is now to have grunt installed locally to be able to use version-specific Gruntfiles
As Florian F suggested, running grunt.cmd works. This is because of the process Windows is looking for your grunt command.
When typing grunt -h Windows will proceed to look for the following files:
./grunt.cmd
./grunt.* (grunt.js is found in this case which is why you see "module is undefined")
%APPDATA%/npm/grunt.cmd
An alternative to using "grunt.cmd" is to use grunter which simply renames the command to grunter... then you no longer have this problem.
To answer this, first we need to understand that the error is caused because it is being executed by Windows Script Host.
Now, run the code from your cmd promt with the following syntax:
>node <application_name>.js
this will allow the Node.js application to open through V8 JavaScript engine(Google's).
P.S: Please reply back if this has helped in resolving your issue else post the problem you are facing after trying this.
I had a similar issue, the problem is file association, I would recommend:
right click on a .js file and choose open with.
then you choose nodejs/node.exe (somewhere in "program files" folder
then make tick box where it says "always open .js files " (paraphrasing)
That should do the trick.
I went through the same issue when running an old Node project.
The issue was with the name of the js file, it was node.js. So the while running the command node node.js, it was opening up a windows dialogue box.
I just changed the name of the file to app.js and the error flew away.
So, in my case i had tryed all the mentioned above with no result.
But i have fund that im dont type: node in the full sentence as the following snipet
node script.js.And remember never understimate your own miscoding.
Solution:
Go to any javascript file with "js" extension. (any file)
Right-Click(mouse) > Properties > "Opens with:" Change...(button)
Choose Notepad ( or any Javascript IDE like VS Code ).

Set Node.js environment variables in WebStorm

Is there any way to set environment variables when running a Node.js app using JetBrains' official Node plugin for WebStorm (and their other IDEs as well)?
It is actually possible
Here is the official doc:
http://www.jetbrains.com/webstorm/webhelp/run-debug-configuration-node-js.html
Here is my screenshot
No, it's not possible from WebStorm, environment variables should be defined in your system.
UPDATE: in the new versions it's possible to set environment variables in the Run/Debug configuration.
I'm new to JetBrains products, i'm not sure if this is the official solution.
Sharing the steps I took resolve this issue.
Note: I'm using NPM package manager.
In WebStorm menu, go to Run -> Edit Configuration -> click + -> npm
then provide the following fields:
Package.json
Command: run
Scripts: start
Environment: MY_ENV_NAME=123456
Click Ok
Then select the run configuration:
Finally got the nodejs server up and running:

Resources