Node Space Dot Command Node JS - node.js

I am coming back to a Node JS script after some time. I am in my development directory/folder with many test JS scripts. I load the script that, by name, looks like the one I want to run. It has the most recent date which supports this point of view. I run the following command:
C:\testscripts>node .
It runs the script successfully. But I can't see how this has happened. My script is what's largely contained in GoogleDrive for Developers Node JS Quickstart I look at the requires, scopes, credentials etc but can't figure out how my dev environment 'knows' which script to run when I use the generic command above?
So I can also run the same script using it's name.
C:\testscripts>node gdocToTextDownload.js
But what is it that lets me leave the file name out and still get the same result? I would appreciate a suggestion here.

Node looks at the main field of package.json and runs the file listed there.
npmjs.com documentation for package.json main
Nodejs.dev documentation for package.json main

Related

Behind-scene after "umi dev"

Just started learning React js and then I found this enterprise-level react application framework called Umi. Since I am just a beginner with Node js too, I am having a hard time understanding what really happened after I typed 'umi dev' in the command line.
I spent some time digging into the source code. My current guess is that somehow umi used another js library called 'webpack-dev-server' to actually run an express server locally. However, I am still confused on how the 'umi dev' command makes all these things happen. Is 'dev' a command? Or is it a class? What should people do if they want a new command like 'umi my-own-command'?
umi is installed by yarn global add umi
i think, you can take a look about ~/.config/yarn/global/node_modules/umi
There's an introduction to umi
there is a file package.json
directorys lib, bin, scripts. and so on
i hope this helps you

Using webhint with angular7

I am trying to incorporate webhint which is a linting tool that
will help you with your site's accessibility, speed, security and more,
by checking your code for best practices and common errors.
So its installation is as follows :-
npm install hint --save-dev
npm create hintrc (creates a config file)
then I add hint to scripts in package json
"hint" : hint
I run the local server using ng serve in one cmd
And I run webhint in other cmd using
npm run hint -- http://localhost:4200
I wanted to run the ng serve/build along with npm run hint.
I tried steps on link https://webhint.io/docs/user-guide/development-flow-integration/local-server/
I also tried &&, | and concurrency but all failed.
What I want is to run both these ng serve/build and npm run hint using one command.
Any help would be appreciated.
When an angular application with multiple components is run and webhint is run, the html or json formatters show errors but line numbers are column -1 and row -1.
Most likely this is because the html of the page is generated on the client side so the line/col don't make a lot of sense as it is generated dynamically. If you tell the browser to so the pages code you only obtain the initial html, and if you go to the elements panel in the devtools line and column don't have sense there.
The errors should have the html of the element with the error and that should hopefully help you identify the template with the issue.
That said, we have plans to improve this experience but need to finish a few things first.
How does webhint traverse the code using routes or urls so I can better understand it ?
When using Chrome or jsdom we wait until the page is loaded and then analyze all the html while keeping track of all the network requests. In the case of the local we analyze all the files in the folder passed as a parameter.
npm run all and concurrency don't work for me. ng serve only keeps running.
Do you have the code somewhere so we can take a look? Enabling the concurrency should launch all tasks simultaneously. Maybe it's a question of adding a delay in webhint or something similar.
Thanks!

How does the openshift build system work?

I'm struggling with how to set up an openshift build, where I have two projects in one. Both (the frontend and the node backend) have their own package.json but only the latter needs to be started.
I'm using the hooks in the .openshift directory, but there seems to be more 'magic' going on in the background. For example nowhere in my build code there is an npm start declared. Openshift seems to run the command automatically. Is there maybe a way to deactivate this behaviour? What is going on the background? Is the build-process defined by the package I'm using? And if so, how to change it?
If all fails, I really would like to use an external build-server. Is that possible?

How to test NodeJs CLI javascript

I need to put some tests around a nodejs command line utilities\modules. No browser involved and I'm using a lot of the "fs" module to work the file system, so i'm not sure a browser based test mechanism would work (sandboxing).
any modules that would help here?
Check out Vorpal.js. This lets you create an interactive CLI in node, in which you can then run custom commands to test the various things you want to test.
Disclaimer: I am its author.

Running Protractor from Node-webkit

Is is possible to run Protractor in any other way except using CLI?
Is there an API call which will simulate the command: 'protractor config file.js'?
I would like to start a test through a node-webkit application, and even though I can connect directly to the ChromeDriver through the directConnect parameter, this is no use if I can't run protractor from inside the script.
Of course, this is in an environment where Node and Protractor aren't available from CLI... simulating a distribution environment where the user doesn't have to install additional apps apart from my node-webkit (hence the node-webkit usage).
Thank you in advance for any pointers!
The protractor command line script boils down to invoking lib/cli.js which mostly deals with parsing commmand-line arguments and then invokes lib/launcher.js to actually start protractor.
I don't think any special concessions have been made in these files to be directly invoked programmatically, but I don't see any particular hurdles either.

Resources