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.
Is it possible to run a JavaScript file with node.js on windows? I have been trying to for hours and can't find any more solutions on the internet that work.
I have a js-file that uses scribbletune which only works with node.js.
I have node.js installed and I installed gitbash because it was recommended in a forum.
I tried to run from command prompt and gitbash but nothing seems to happen.
What am I doing wrong? Any help would be very much appreciated.
There is no need to install gitbash to use Node on Windows. It's a handy thing to have if you're used to a *nix environment. If you're not, it just gives you something more to learn, which isn't helpful if you're already in the middle of trying to learn Node.
Just:
Get the Windows installer from https://nodejs.org/en/download/
Run the Windows installer
Create a directory for your project
Open a Command Prompt Window to get a command line
Switch to your project directory
(Optional, but a good idea) Use npm init to create a package.json file (it'll walk you through it)
Install any libs you're going to be using via npm (for instance, npm install scribbletune from your command prompt window)
Put your JavaScript files in that directory
Use node main.js at the command line to run your main file (whatever it's called; main.js is just a placeholder)
Inorder to run a js (java script file) file
step 1. u need to go to the file location where u want to run.
step 2. just use "shift +right click".
u will see a pop-up and go to powershell or cmd.
step 3. type "node FILENAME.js"
final step: you will see the result ^.^
I am trying to get up and running with Meteor and seeing what it can offer, while I like it overall, it seems it's a very very rigid system.
I set up a small testing setup using Velocity, it opens a small overlay window on the side which has a class of "velocityOverlay". The overlay is really small and makes error stack traces wrap. All I wanted to do was to edit the css of the "velocityOverlay" and increase the width.
I somehow (after wasting time) managed to find that Meteor is actually putting all the packages in my user directory by default, once I found that, I found the needed css file...
velocity_html-reporter/.0.5.1.aykpxq++os+web.browser+web.cordova/web.browser/packages/velocity_html-reporter/lib/client-report.less.css
And I did a small edit to the width, next thing you know the meteor app crashes when trying to launch using the "meteor" command throwing a "Error: couldn't read entire resource" error. I can't even edit the bootstrap.css file I installed using "ian_bootstrap-3".
Further more, I can't find any way to install packages locally just for my particular project, what if I wanted to modify a package only for my particular project? this is very easy to do in vanilla Node.js, you simply don't use the "-g" when using "npm install".
To add to that, within my project root, there is another ".meteor/local/build/web.browser" folder with most of the global package files replicated again. When does Meteor use which? This is very confusing.
You can run a package locally very easily.
Download it from Github (for example) and put it in the packages/ directory of your application like this /packages/package_name.
Then add it to your application with the same meteor add package_name command as usual.
Meteor will automatically look in the local folder before anywhere else and compile the package with the rest of your code.
This allows you to do any modification you want on the package and test it locally before publishing it to the registry.
Also, folders located in .meteor/local/* are used for building purpose only and are generated automatically by Meteor. So it is not the best place to edit the files!
This worked for me https://atmospherejs.com/i/publishing. mrt link-package didn't work for me, might just be outdated code.
Steps:
Download (or clone) package from GitHub to local dir
Stop meteor if running
2.1. Make sure you have a packages folder: mkdir packages
Locally link your package:
3.1 If you have mrt installed: Run mrt link-package /path/to/package in a project dir
3.2 If you don't have mrt: ln -s /path/to/package packages/package
Then run meteor add developer:package-name, do not forget to change package name
Run meteor in a project dir
From now any changes in developer:package-name package folder will cause rebuilding of project app
Download the package and place it in new package directory in your project root.
open the package.js inside the downloaded package and remove the author's name in the property "name:"
e.g: - name:'dburles:google-maps' to name:'google-maps'
then run
meteor add google-maps
I am using XCode 5.0.2 and Cordova 3.4.0-0.1.3 - What I find is after creating the project using the Cordova CLI and opening in XCode, no changes to the index.html file and index.js file are ever carried over to the simulator when I click run.
I have to open terminal and issues a Cordova Build command and then run the simulator and it works
I followed all the instructions here:
Phonegap - developing and launching app on simulator
xcode 4 + phonegap ... not update JS upon build?
And none of it works! any one a have a solution to this, because having to switch back and forth is becoming a pain.
You can add a pre-action script to your XCode project's build. To do this:
Select Product > Scheme > Edit Scheme from the menu (or ⌘ < on keyboard)
Select Build > Pre-actions from the left
Click + and select "New Run Script Action"
Add a script like this:
cd /path/to/your/cordova/project/
cordova prepare ios > xcode-prepare-results.txt
Now XCode should always run cordova prepare before building your project so you don't have to jump to terminal. You can see the output of prepare in the file xcode-prepare-results.txt.
Note, that depending on how your cordova executable is set up and which shell you use, you might have to either change the shell or modify your PATH in order for the script to find cordova.
So after much searching I seem to have found a solution that works, here is what I did. After looking at other Stackoverflow questions I found someone that said this worked for them.
Find the file called copy-www-build-step.sh.
Mine was in
[project_folder]/platforms/ios/cordova/lib/copy-www-build-step.sh
In that file, find the lines beginning rsync -a "...
Add -c to the rsync lines, so they ready rsync -a -c "...
Well I tried that and it did not work on its own. I also tried the answer from Ville and that pulled closer but no cigar. Finally I took what the command from Ville and put it in the copy-www-build-step.sh file
so my top line is now
cd /path/to/your/cordova/project/
cordova prepare
SRC_DIR="www/"
DST_DIR="$BUILT_PRODUCTS_DIR/$FULL_PRODUCT_NAME/www"
COPY_HIDDEN=
ORIG_IFS=$IFS
IFS=$(echo -en "\n\b")
.....
.....
.....etc etc
And now I make change , and click run , bam all is updated. I hope this helps someone else.
Other answers in this thread either didn't work for me or screwed up cordova plugins e.g. InAppBrowser, so i finally came up with this:
Edit the file copy-www-build-step.sh and add the following row in the beginning:
cp -fR ../../www/ www/
so it should look like:
...
cp -fR ../../www/ www/ # new code
SRC_DIR="www/"
...
This way your code will be updated properly and your plugins will work
I also edited the copy-www-build-step.sh file, however you don't want to use an absolute path from your User folder. If you are working with other developers you would have to change that every time you check out code.
It's not a big deal, just change:
SRC_DIR="www/"
To:
SRC_DIR="../../www/"
UPDATE
Worked for me on Cordova and Phonegap.
To have the source files automatically copied from the www source directory to the platforms/ios/www directory when you click the Run button in XCode:
In XCode, choose Product->Scheme->Edit Scheme...
Expand the triangle for Build->Pre-actions
Click the "+" to create a new Pre-action
You can leave the "Shell" setting blank.
Set "Provide build settings from" to the project you are building. This is important.
In the script area enter:
cd ${PROJECT_DIR}/../..
echo "--- Start ---" > xcode-prepare-ios-results.txt
echo "Running cordova prepare ios command..."
pwd >> xcode-prepare-ios-results.txt
cordova prepare ios --verbose >> xcode-prepare-ios-results.txt
echo "--- Finished ---" >> xcode-prepare-ios-results.txt
This works for me with XCode 8.2 and Apache Cordova 6.x
I suggest you clean before build your xcode project. And one more thing, make sure you build again your project using cordova build, not inside xcode because it's totally different.
cordova build yourproject
#Ksliman
I modified you code a bit to work on my system and make slight bit more generic.
top of file copy-www-build-step.sh
## New Code Begin ###
cd ../../
PATH=${PATH}:/usr/local/bin
cordova prepare ios
## New Code End ###
SRC_DIR="www/"
simply type:
cordova prepare
on your terminal and run your project again in Xcode
Simple solutions is to build the app with cordova using:
sudo cordova build ios
Then go to xcode > Product > Clean
Then go to xcode > Run (Play Button)
Run "cordova prepare ios" during the building phases:
Open Xcode.
Select your project.
Go to "Build Phases".
Go on "+" to add a "New Run Script Phase".
Move this section before "Copy www directory".
Add the following lines (for Mac):
cd /Users/*/YOUR_PROJECT_FOLDER (Change your project folder)
/Users/*/.nvm/versions/node/v?.?.?/bin/node node_modules/cordova/bin/cordova prepare ios (Change the path to node version)
After "Play" the www-folder will automatically refresh!
All I had to do was to include the full absolute src path for my project. For example:
From your project directory, vim platforms/ios/cordova/lib/copy-www-build-step.sh
change SRC_DIR to the absolute path of your www, SRC_DIR="/Users/michael/Documents/Development/SampleMobileApp/www/"
Save, build, and you should be good to go.
I found that sometimes Cordova gets confused... you need to do a "cordova platform rm ios" (just leave your plugins alone), and then do a "cordova platform add iOS", which will reinstall all your plugins into your platform... then try your build again.
Every time I use cordova build its overrides content in my platform specific www file. So I use cordova compile instead.
From help:
compile <platforms> compiles platform project without preparing it
It is important to just compile the changes not to build entire projects especially if you creating mobile app for many platforms and you have to do some platform specific improvements.
For me, there was an error in my code. I simply needed to run npm start to locate it.
If you are directly changing html from the Xcode, then you should change the code/html of the staging folder, not main folder
In the staging folder you will get same structure which you have in the main folder, but it will reflected directly in the xcode (iOS) build
Staging folder
Note: The changes you made in the xcode will be replace when you build again from the cordova build/run, so please copy your changes in the main folder before doing firing cordova commands
You can get more information from this answer: Purpose of Staging folder in PhoneGap 3.4? Only changes to index.html in this folder get recognized?
This is the correct solution taken from:
Cordova + Xcode 7.3 (html + Javascript) not changed or updated when build and emulate
I am trying to install my own firefox plugin. I follow this tutorial. But each time this gives me following error:-
Firefox could not install the file at
file:///home/ubuntu/googbar.xpi
because: Install script not found
-204
That error means that your file doesn't have an install.rdf file. Please note that it needs to be at the top level of the XPI archive. So maybe you made a mistake packing the file and install.rdf landed in a subdirectory. You can check the list of files using unzip -l googbar.xpi command, it should list install.rdf without a directory name before it.