I just started experimenting with phantomjs via terminal/bash Version 2.5.3 (343.7), on osx 10.10.4. The ready to use binary was installed.
I was able to set phantomjs on my PATH with symbolical linking. Prior to that I had to directly launch the executable or enter its absolute path.
When I try to launch a .js file with phantomjs, for example hello.js, I get " Can't open 'hello.js' ". If I enter the absolute path of the .js file it works:
console.log('Hello, world! It works :D');
phantom.exit();
Johns-MacBook-Pro:~ john$ phantomjs hello.js
Can't open 'hello.js'
VS
console.log('Hello, world! It works :D');
phantom.exit();
Johns-MacBook-Pro:~ john$ phantomjs /Users/john/Documents/phantomjs-1.9.2-macosx/examples/hello.js
Hello, world! It works :D
Johns-MacBook-Pro:~ john$
My question is: Do I need to symbolically link the folder where the .js files
are located with /usr/local/bin/ to ensure that it is also on my PATH or is there another way that
the .js files can be launched with phantomjs, without having to enter the absolute path every time?
I did search before posting this question but I'm uncertain as to how I should interpret everything I found :( The most significant, and somewhat relevant information I found referenced to node.js as the default to execute .js files in terminal.
Please note that currently, the hello.js file I am using is located in
/Users/john/Documents/phantomjs-1.9.2-macosx/examples/hello.js
and phantomjs is located in
/Users/john/Documents/phantomjs-1.9.2-macosx/bin/phantomjs
Please let me know if you need further information and thank you for taking the time to read my question! :)
You need to be in the folder that the file is in to run it directly. If you are in the folder /Users/john/Documents/phantomjs-1.9.2-macosx/examples/ you should be able to run phantomjs hello.js.
# Change directory to where the file is you want to run in phantom
cd /Users/john/Documents/phantomjs-1.9.2-macosx/examples/
# Run the file with phantom
phamtomjs hello.js
Related
New coder here. As the title suggests, I spent the past two hours trying to run a simple Javascript on VSC with no avail. Could someone help me set my sandbox up? Here is a screenshot.
Much appreciated!
kt
Downloaded VSC
Downloaded nodejs
Entered "node scriptname.js" in terminal
Error message above
Your specific error is caused by you running node from the console and providing the wrong path to test.js.
You are in the Desktop directory and just specifying a file name, so Node is looking for test.js in the Desktop directory.
You have saved test.js in a directory called Coding Practice.
You need to either:
cd to the correct directory or
Provide the path to the directory as part of the second argument
Typically, when using VS Code, you would pick the Open Folder option from the File menu to work within your project's root directory (i.e. Coding Practice) which will provide you with a file list and do things like open the terminal in that directory by default.
Once you solve that problem you will run into your second problem.
The contents of test.js isn't JavaScript!
It's an HTML document with JavaScript embedded in it.
You need to:
Give it a .html file extension and
Open it using a web browser and not with Node.js (the traditional way to do that from within VS Code is with the live server extension but you'll really want to have VS code open in the right directory (as above) for that.)
You can't even remove the HTML from the file and run it with Node.js because alert (the function you call) is a Web API and not core JavaScript nor a Node.js API.
I just recently installed this version of Linux and when ever I do code fileName in the terminal it makes a whole new file. IS there a way for me to open an already existing code file I have?
Thanks for taking your time and effort to answer this question!
Yes, there is!
You need to be on the same folder of the file. For example, if the path of your file is /home/Downloads/ you need to use cd Downloads and then try to open the file. However, note that the code command that you are trying to use is the default command to open the file in the vscode. If you want to open the file using the default text editor in Linux, usually you have to write gedit filename in your terminal
Personally, I open the directory of the project and run command code .
This opens it with VSCode, but that's okay because most often I will need all other files anyways. Brackets is brackets .
I am using WebStorm on Windows to work on node.js projects.
Recently, when I open one of my projects that are located on the OneDrive directory I got the 'Error: Please specify path to JavaScript file correctly' when I run a .JS file. However if I move the same project folder to an other directory (Desktop for example) it works correctly.
PS: Nodemon keeps restarting forever when running on the onedrive project.
How can I fix it?
Please see https://youtrack.jetbrains.com/issue/IDEABKL-7619#comment=27-2504574 for possible workaround.
And, if possible, use some VCS for sharing instead of OneDrive, see https://intellij-support.jetbrains.com/hc/articles/206544839.
I was following the React Native document to create a signed APK.
Source
Setting up Gradle variables
Place the my-release-key.keystore file under the android/app directory
in your project folder.
Edit the file ~/.gradle/gradle.properties and add the following
MYAPP_RELEASE_STORE_FILE=my-release-key.keystore
MYAPP_RELEASE_KEY_ALIAS=my-key-alias
MYAPP_RELEASE_STORE_PASSWORD=*****
MYAPP_RELEASE_KEY_PASSWORD=*****
Originally, I thought ~/.gradle is <project folder>/android/.gradle. However, it is not... In the command line, I ran the cd ~/.gradle/ command and it says:
The system cannot find the path specified.
Would you please let me know where is this folder (in Windows), so I can create gradle.properties? Thank you.
~ is used to represent the home directory (on unix based systems). When on windows the equivalent would be C:\Users\username\.gradle dir. Of course username would have to be changed for your username. This is where it is on my computer.
I followed these instructions (except for copying the executable to my PATH because I cannot seem to find it and it does not seem necessary). Then I made a file called image_render.js in my public javascripts directory with
console.log('Hello, world!');
phantom.exit();
inside it, saved it, and ran phantomjs render_image.js in my terminal.
However, my terminal does not recognize the command:
-bash: phantomjs: command not found
What have I done wrong?
The PATH really is the important part. You can skip it, however, if you specify the absolute path. Try something like this:
/path/to/phantomjs render_image.js
...but that can get tiring. For a quick way to add it to your PATH, from the directory of the phantomjs executable, symbolically link it into /usr/local/bin:
sudo ln -s /path/to/phantomjs /usr/local/bin/
/usr/local/bin is likely on your PATH.
add this line to this file /home/optiman2/.bashrc
PATH=/home/optiman2/phantomjs/bin:$PATH
this worked for me.
and remember to use this command, before test phantomjs:
source .bashrc
FYI to Windows users upgrading to version 2.0.0 - the executable has moved. In addition to changing your PATH environment variable to 2.0.0, you'll need to add \bin to the end of the PATH that you had for the 1.x.x.
Mac PATH suggested setup:
Open Terminal.
Type vi ~/.bash_profile and hit enter (this opens or creates your bash_profile where you can customize Terminal commands).
Press i to enter insert/edit mode then type alias phantomjs='~/PATH/TO/phantomjs' and be sure to replace ~/PATH/TO/phantomjs with something like ~/Documents/PhantomJS/bin/phantomsj or wherever the file exists on your machine.
Press esc to exit insert/edit mode then type :x and hit enter to save the file.
Quit and re-open Terminal.
Type phantomjs and hit enter. If you see the prompt phantomjs> then you're all set.
Type phantom.exit() to end the PhantomJS program.
Now you can navigate to any folder and run PhantomJS by simply typing phantomjs. This is helpful when saving screenshots because the images will be saved inside the folder that's active in your Terminal.
Whatever command is just a executable file. To be accessible by type its name directly, you have to put it into a path that system will look for that file directly.
For linux/OSX, it's /usr/bin or /usr/local/bin. Which really works? Well, it depends...
So what worked for me is extract the 'phantomjs.tar.bz2' source file to somewhere and copy the executable file to /usr/local/bin like this:
cp path-of-extracted-phantomjs/bin/phantomjs /usr/local/bin