Why can't I run my node.js express web application - node.js

Node.js and the express generator are really handy and simple to understand. I cannot however get my server to start by running c:\my-application-root>DEBUG=my-application ./bin/www
Windows doesn’t seem to understand that command. I can however run it by calling node ./bin/www
Am i missing something?

Did you try set DEBUG=my-application followed by node ./bin/www? Windows does not allow setting an environment variable in the way that Linux and others do.

1st command 'set DEBUG=my-application'.2nd command 'npm start'

First you need to go the cmd that is supported by node (search for node cmd when you click in windows icon if you're using windows 7)
type
set DEBUG=my-application
Second
simply cd c:\my-application\bin\
Then type
node www
www is the file that contains the script needed by node to run your server, DEBUG if set as an environment variable will also help you run node against it since the path will be known

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...'

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?

how can I debug a node app that is started via the command line (cli) like forever or supervisor?

I'm familiar with debugging my own node apps (usually with node-inspector). Today I'd like to debug someone else's program. I'm trying to track down an issue with supervisor. So naturally I just add a --debug (or debug-brk) to the command call, but it passes that to the code that it is supervising.
I've tried adding debugger lines to the js file for supervisor but that didn't work (probably because no debugger was attached at that time). There's a bit of a race here -- I need to start the debugger and attach it to the supervisor process after it starts but before it processes its arguments from the command line.
What I really want to do here is stop supervisor and debug it before it processes its command line arguments. How can I do this?
I had the same problem while developing my hexo blog. The documentation isn't all that complete yet so I find myself needing to reverse engineer at times.
The basic idea is that in Node.js even your cli apps are simply normal node apps that you are exposing to the OS command line interface. On Unix systems you are using this line:
#!/usr/bin/env node
To allow the environment to execute the script.
Many cli based node apps try to insist that you install them globally with the -g option.
npm install -g node-inspector
I personally prefer to have as much control of my development environment as I can get, so I prefer to break some conventions and check my node_modules in to source control along with installing everything I can locally by dropping the -g.
npm install node-inspector
Now you don't have to do this in order to make this work, I'm just describing this setup because it relates to your question. When I run node-inspector I can't simply use:
node-inspector
Instead I must explicitly invoke it from within my project. I do this by executing the symlink in my node_modules/.bin folder:
node_modules/.bin/node-inspector
Now I'm running node-inspector just like you.
Next all I need to do is start the cli process in debug and optionally pass params to it:
node --debug-brk node_modules/.bin/hexo generate
Note I am explicitly calling the symlink here and not simply:
node --debug-brk hexo generate
If I tried the line above I would get an error: "Error: Cannot find module".
I hope this helps.

Rerun node app on WebStorm after code change

I recently started to use WebStorm and before this I used to use nodemon as a supervisor, so it watches any code change and restart the server.
How can I reach the same effect running node by the IDE?
Thanks!
[EDIT]
While there's no 9 version/live edit I'm posting my solution:
It's just have nodemon installed globaly and used it as a Node Parameter in the project configuration.
More details and screenshot below:
Discover where is the nodemon's path;
Here (OSX) is "/usr/local/bin/nodemon" and it could be discovered using "which nodemon" (on terminal);
Use this path in the Node Parameter field;
Go to Run > Edit configurations, choose your configuration below the Node.js option at left;
Screen shot for detail:
https://photos-4.dropbox.com/t/1/AAC1WJBhh1RUnIBZEaG3YQ80iMswJH2XmFqb4GtiYwqj2A/12/11986044/png/1024x768/3/1413997200/0/2/Captura%20de%20tela%202014-10-22%2013.52.47.png/exYBAGzU3uZwj45i3XxZkgPKb_mfyL_O_q3EFRK5pFk
Possible since WebStorm 9 - see http://blog.jetbrains.com/webstorm/2014/08/live-edit-updates-in-webstorm-9/

How to configure forever in nodeclipse?

I have installed "Enide Studio 2014" on Windows 7. Then I created an "Node.js Express Project". Everything went smoothly, a new project was created. I was able to run it without any problems.
As stopping and starting node server everytime I make any changes in the code takes unnecessary efort while developing, I wanted eclipse to "monitor" changes and restart node accordingly. As nodeclipse provides an option for this purpose, I tried to configure forever as node monitor.
In Nodeclipse preferences Node Path was set as "D:\Software\Development\NodeJS\node.exe" as it should be. Forever was installed in "D:\Software\Development\NodeJS\node_modules\forever\bin\forever" so I set "Node monitor path" in as that.
After this I was not able to run the project again.
When I check console output, the command issued (and failed) was:
node D:\Software\Development\NodeJS\node_modules\forever\bin\forever D:\calismaalani\nodejs\deneme\app.js
I copied the command line and issued it on the command window myself and got:
warn: --minUptime not set. Defaulting to: 1000ms
warn: --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
error: Cannot start forever
error: script D:\Software\Development\NodeJS\D:\calismaalani\nodejs\deneme\app.js does not exist.
As it is clearly seen, Nodeclipse was trying to add node_home path to the absolute path for my app. I have tried to set some environment variables but could not manage to get the right path for my app.
What is wrong here? How can I fix this?
Since Nodeclipse 0.17 Run with Node monitor is hidden as it raised more questions then solved.
Please launch via CLI as forever and TCF-Terminal is nice shell integration into Eclipse,
so you can have several forever instances running for different project in separate tabs.
You can specify the "Node options" path in Nodeclipse preferences as D:\Software\Development\NodeJS\node_modules\forever\bin\forever --sourceDir . and Nodeclipse should automatically use forever to start your node Js application.
I use nodeclipse version 1.0.2.x and use nodemon to monitor the application and it works fine for me.
Edit:
In your case, you cannot pass the absolute path to forever . if you need to ,you can use the "--sourceDir . " option of forever. The --sourceDir and the "." option looks for the full path of the application. So your command will look as follows:
node D:\Software\Development\NodeJS\node_modules\forever\bin\forever --sourceDir . D:\calismaalani\nodejs\deneme\app.js
You need to give Node monitor path as D:\Software\Development\NodeJS\node_modules\forever\bin\forever --sourceDir .
Incase you are using nodemon, you need to give the path as C:\Users\ashwin_valento\AppData\Roaming\npm\node_modules\nodemon\bin\nodemon.js --watch

Resources