Someone shared with me the code of an application, now I am trying to study it, understand the code before moving on to the next stage of improving it. Funny that the developer is missing in action and he didn't document anything.
Now, launching the app only has been a problem and I notice the error is coming from package.json file. This is the section with the code error:
"scripts": {
"start": "PORT=3333 bash -c 'node scripts/start.js'",
"build": "node scripts/build.js",
"test": "node scripts/test.js --env=jsdom"
},
Now I am running this app on VS CODE on windows 10. I understand on windows you don't have to declare the port at all on that start line but I am wondering how can I rewrite the start line so that to have it working. Any ideas will be highly appreciated.
The Linux shell command
PORT=3333 bash -c 'node scripts/start.js'
starts a new bash process with the environment variable PORT set to 3333, cf. e.g. How do I set an environment variable on the command line.
For cross-pltform compatibility, you can use the cross-env library. (Note however that it's only in maintainance mode.) You can probably use this:
cross-env PORT=3333 node scripts/start.js
Related
Working with node.js, I stumbled upon a behavior I cannot explain regarding command line arguments :
I've got a program which takes a regex to detect test files. This regex is passed via a command line argument :
node index.js --require src/**/*.js
When I do that, I obtain what I imagined. Let's say for the example I got the following files detected in my src folder (I log with a simple console.log(process.argv)) :
a.js
b.js
shared/c.js
shared/d.js
Now if I configure a npm script which launch the same command :
"test": "node index.js --require src/**/*.js
and launch it :
npm test
The result is :
a.js
b.js
Can someone explain to me why this is happening 😅 ? Thanks
I created a mini repo to reproduce for those interested (I run node 16.19.0)
you need to execute the command using bash to make use of its filename wildcard extensions.
"test": "bash -c 'node index.js --require src/**/*.js'"
npm uses /bin/sh by default to execute your scripts. Unlike bash or zsh (which you are probably using on the command line), sh does not understand **.
You can change the shell used by npm with:
npm config set script-shell bash
I'm running a node.js application and I installed nodemon.
Unfortunately, I installed it from the CMD on Windows (I keep having problems installing new packages from VS, as it doesn't update the PATH). So once I installed it from CMD, I run a command using nodemom, then Windows asked me what tool to use. I had a few choices, among them VS, but I pressed Windows Bash Script...since then even though I run nodemom from VS terminal, I got the same error as attached again and again.
I have tried to disable WBS, but I didnt find the exact Enable/Disable settings in the registry.
I tried this too: https://answers.microsoft.com/en-us/windows/forum/windows_vista-windows_programs/microsoft-jscript-error-800a03ea/e8723445-77ea-4b13-b13e-afde15f22bfb
enter image description here
I have checked the PATH and seems correct both on the user and system env variables are pointing to: ...npm\node_modules\nodemon\bin\
What else can I do?
Thanks in advance!
When I was trying to run a simple node.js express app I saw the same error message when I had the following code in my package.json:
{
...
"start": "nodemon --exec src/index.js",
...
}
Then Windows was also asking me which program I want to use to execute it.
The fix for me was to set the correct interpreter (in my case node).
{
...
"start": "nodemon --exec node src/index.js",
...
}
if you use window and babel to compile then you can try:
{
...
"start": "nodemon --exec ./node_modules/.bin/babel-node ./src/index.js",
...
}
Trying to debug an NPM script from within Webstorm. The application runs through the NPM scripts, but when debugging the script it always crashes. I know that there is the flag $NODE_DEBUG_OPTION, but adding that doesn't seem to work.
Script:
"dev": "npm run dev:server & npm run build:client:watch",
"dev:server": "npm run build:server:watch & nodemon --harmony lib/server",
"build:client:watch": "WEBPACK_DEV=true NODE_ENV=development STACK=local node lib/server/webpack",
"build:server:watch": "npm run transpile:watch -- -d lib/common src/common & npm run transpile:watch -- -d lib/server src/server",
"transpile": "BABEL_ENV=node babel",
"transpile:watch": "npm run transpile -- --watch",
According to Webstorm: To debug the "dev" script, make sure the $NODE_DEBUG_OPTION string is specified as the first argument for the node command you'd like to debug. For example: { "start": "node $NODE_DEBUG_OPTION server.js" }
But even when adding this in different places it will still give me an error. Any suggestions?
For anyone reading this in 2020, you just need to right-click the script in the NPM panel and select "Debug ".
You can then set breakpoints in the script and debug in the Debug panel panes, Debugger, Console, etc..
To re-run the script, click the bug icon in the Debug panel.
Probably you are using node8, where this will not work because in node 8 V8 debugger API had been superseded by the V8 inspector API. For more info look at this issue, In previous versions of nodejs this works. For node 8 you should check the WebStorm site, they have information about how to work with the new inspector protocol https://www.jetbrains.com/help/webstorm/run-debug-configuration-node-js.html?search=node
Console output on npm run build failure:
'.' is not recognized as an internal or external command, operable
program or batch file.
And the relevant npm file:
"scripts": {
"postinstall": "jspm install && npm run build",
"start": "http-server",
"build": "./bin/build-code",
"build-home": "./bin/build-home -dw",
"build-common-deps": "./bin/build-common-deps -dw",
"build-navbar": "./bin/build-navbar -dw",
"build-root": "./bin/build-root -dw",
"build-angular1": "./bin/build-angular1 -dw",
"build-react": "./bin/build-react -w",
"build-preact": "./bin/build-preact -dw",
"build-vanilla": "./bin/build-vanillajs",
"build-angular2": "./bin/build-angular2 -dw"
}
Looks like it's not understanding the pathing to the ./bin/build-code script location. From what I understand, it looks for files from the package.json's location? So, if the app has a bin folder in the same dir as package.json, then this is the correct pathing to the build-code script, which is within the bin folder. What gives? Using PowerShell to run npm run build if it matters.
P.S. I tried with basic Command Prompt - no changes. Someone running the same build (both of us just pulled from repo) on Cygwin said they had to "Change dos endings to unix", which doesn't tell me much and doesn't seem to be the issue.
Looks to me like npm is invoking batch scripts. Batch files are run in CMD.exe (even when invoked from PowerShell), which doesn't recognize / as a path separator. That's where the error message comes from.
Replace the forward slashes with \ (or \\ if they require escaping).
I'm having trouble installing Selenium and I'm completely lost
I followed this documentation by the letter and looked around the site and the web for a while now and came to a dead end. Like I said in the title I'm using Chrome and Javascript for this.
[Documentation]http://selenium.googlecode.com/git/docs/api/javascript/index.html
So true with the documentation, the first thing I did was installing the "selenium-webdriver" which I opened up cmd and typed "npm install selenium-webdriver". It responded with saying what directory it installed and the version it installed which was 2.42.1.
After this I installed the ChromeDriver 2.10 from their home download page. After this I unziped the file and moved chromedriver.exe to "node_modules\selenium-webdriver\ChromeDriver" and added it to my systems environmental variables.
So then the next step was to test it, so I copy pasted "npm test selenium-webdriver" into the cmd and got this following error. [Error]http://imgur.com/xIYE3oa I also tried running ChromeDriver after I kept running into this error and tried it again to get the same result. It doesn't tell me anything other then...
Starting ChromeDriver on port 9515
Only local connections are allowed.
Thank you in advance.
First, make sure that you have Mocha installed by running npm install mocha.
You will then want to edit the "scripts" section of the package.json file for selenium-webdriver to match the following:
"scripts": {
"test": "mocha -R list --recursive test"
},
After completing those two steps, you should be able to run your tests with the npm test selenium-webdriver command.