After npm reads package.json, what runs Electron? - javascript

I'm just starting to learn about how JavaScript, HTML, and Electron all work, and I want to know what runs electron . in the "scripts" -> "start" of package.json, because I can't tell what does and that kind of wizardry makes me nervous.
According to the man pages for npm, what npm start does is that it reads the package.json, looks at the script under "scripts" -> "start" -> some_script, and then runs some_script. Sometimes, some_script is something like node foobar.js, which makes sense to me, since I can run that from the command line. NodeJS is executing foobar.js. However, in the case of the electron-api-demos, some_script is electron .
You can download and run electron-api-demos via
git clone https://github.com/electron/electron-api-demos
cd electron-api-demos/
npm install && npm start
In order to try to figure out what is running electron ., I've run it in the node shell, and I've tried running node main.js. I've even tried opening up the node shell and running
electron-api-demos#2.0.2 start $DIR/electron-api-demos
electron .
(which is exactly the output of npm start). None of them worked, because none of them started up the Electron application. At this point I'm very puzzled at how, exactly, the start script gets executed at all.
So I guess my question is: does there exist a command (that I can use on the command line) to start up this Electron application, without using npm? If not, what is npm calling to start up this Electron app?
I apologize if this question has been asked before, but I all the sources I found didn't seem to go into any further detail about what, exactly, is done when npm start is run and how it executes electron . . Thank you for your time!

Command line interfaces installed with npm are put in the node_modules/.bin/ directory. You can't just run them from the command line because that directory isn't in your PATH (unless you put it there, or you installed it globally).
So, if you want to run electron without npm start, you can run ./node_modules/.bin/electron .. Since this is a bit verbose, newer versions of npm provide the command npx to run things without the ./node_modules/.bin/ part, so npx electron . also works.
Since npm scripts often use the packages you've installed, they automatically add node_modules/.bin/ to the PATH before running your command. As a result, the start script can just reference electron directly.
npx can do some other cool things too – npm has a blog post about it.

When you run npm start , it by default run command corresponding "start" key of script property of package.json like
"script":{
"start": "ng serve",
"launch":"electron main.js" or "electron ." // main.js located in the same dir
"test": " ng test"
}
same when you run npm run launch it will trigger the command corresponding of the "launch" key of script property of package.json file. like run electron main.js command and your application will launched.
so if you want to run the your electron application directly like electron main.js then install the electron module globally using command npm install electron -g then simply run the electron main.js command and your application will start.

Related

why "meteor npm install" is not working on gitpod workspace?

I am new to gitpod.io, I am trying to open a meteor project on gitpod.io and when I type "meteor npm install", it's showing "bash: meteor: command not found", however, if I try "npm install" it's working fine.
Please help me with the issue.
The reason is that meteor is not installed in the default workspace Docker image.
You can run curl https://install.meteor.com/ | sh in your workspace. You'll get a message like this:
Meteor 1.10.2 has been installed in your home directory (~/.meteor).
Writing a launcher script to /usr/local/bin/meteor for your convenience.
This may prompt for your password.
sudo: effective uid is not 0, is /usr/bin/sudo on a file system with the 'nosuid' option set or an NFS file system without root privileges?
Couldn't write the launcher script. Please either:
(1) Run the following as root:
cp "/home/gitpod/.meteor/packages/meteor-tool/1.10.2/mt-os.linux.x86_64/scripts/admin/launch-meteor" /usr/bin/meteor
(2) Add "$HOME/.meteor" to your path, or
(3) Rerun this command to try again.
Then to get started, take a look at 'meteor --help' or see the docs at
docs.meteor.com.
Since you don't have root rights, a script in /usr/local/bin/ cannot installed by this way. However, you can still use meteor like this:
$ ~/.meteor/meteor
An alternative would be to add your own Dockerfile as described in the docs: https://www.gitpod.io/docs/config-docker/
By this, you can install meteor with root rights.

Unable to test my react program, yarn start and test don't work

So I have JUST started learning React Native to try and learn app development. So I started with a tutorial.
Everything was going fine until I tried running the command yarn start in the terminal to start the server and program and I got the following error message:
error Command "start" not found.
I also tried yarn test but got a similar error:
error Command "test" not found.
I started doing research on why this would happen but I haven't found a solution yet. As you can see from the image my package.json has the start and test commands in it
I've checked for yarn with yarn --version and it gives me 1.17.3 so I know it exists. I also have node installed.
I should be able to start the app with the yarn start command as he does it in the tutorial but it won't find the command.
It looks like you're trying to run the yarn test inside the parent folder of where the package.json is located. Try to cd into the react-tut/ folder using cd react-tut and then run yarn test. This should execute the test script that you have in the package.json file, as expected.

Setting Up Flow in An Existing Project

Am running Ubuntu 16.04.
I am setting up Flow as per the instructions in the link, however, on the next page (usage), where we are directed to run the command:
flow init
I get the error:
No command found...
Which makes sense as flow was not installed globally, but as a dev-dependency within the existing project directory. They also recommend & I quote:
Flow works best when installed per-project with explicit versioning rather than globally.
So, my question is, am I missing a step in the installation of flow, which is causing the error? Or should I go ahead & yarn add flow globally.
Flow Installation Instructions:
https://flow.org/en/docs/install/
Yarn will only install globally if you run # yarn global <add/bin/ls/remove/upgrade> [--prefix]. Using $ yarn add --dev flow-bin as the documentation states will be sufficient. Then, you should run $ yarn run flow.
The full instructions are here, and you can follow it with no problems.
You can also install it using npm instead of yarn:
$ npm install --save flow-bin
Edit
To get the flow init command to work you have to install Flow CLI globally, as the local flow binary won't be in your $PATH environment variable. The command is almost the same:
# npm install --global flow-bin
Alternatively you can execute the binary from within your local path. Something like: $ ./node_modules/.bin/flow init

How do I modify the node startup command in Open Shift?

I'm using ES6 with babel-node to create my app and I require my app to start with the command babel-node app.js. This command is listed in scripts: start in my package.json so the command npm start runs the correct command.
Open shift starts node apps with node + what ever script is set in the main property of your package.json file. In my case its "main": "app.js". So this command is run node app.js.
The server is choking on the first ES6 it encounters which makes sense. I can't figure out how to configure openshift to run babel-node or npm start to start up my app.
Here is my package.json file -> https://gist.github.com/jkinman/2cc57ce5fae5817d6bca
You shouldn't run your server with babel-node, which is memory intensive and not meant for production. Instead, you should use the require hook by creating a file start.js (name unimportant) with the following content:
require('babel-core/register')
require('./app.js')
// or server.js or whatever you use to normally start you app
Then you can start your server with node start.js.

Trouble with installing Selenium(ChromeDriver, Javascript) on Windows 7

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.

Categories