Bitnami Mean Stack - javascript

I have installed mean stack manager, but when I run command using node terminal console.log("Hello World") it works fine, but whenever I put Javascript sample file to any folder or anywhere in the mean stack install directory or install modules every it don't console the file, so I need your suggestions to where I have to put the Javascript file in mean stack manager to console the file.
Bitnami MEAN STACK MANAGER

Bitnami developer here.
The easiest way to play with node is using its interactive shell. Go to your installdir (in your case D:\New Programmes\New Server), double click on use_meanstack and execute:
$ node
Then, you should see > indicating that node is waiting for instructions.
You can also write all the instructions in a file with js extension (sample.js) execute it directly using:
$ node sample.js
You can place this file anywhere you want. By default, Meant Stack working directory is installdir, so you can place you file into D:\New Programmes\New Server to test it directly writing $ node sample.js. However, I think it would be a good pratice to place it under nodejs folder (in your case D:\New Programmes\New Server\nodejs). If you put sample.js there, you should execute
$ node nodejs\sample.js
I hope it helps

Related

Nodejs won't execute my js file the way an author of a book says

Good morning, beginner here.
Im reading a book where the author tells me to run a command from the command line to execute a program made in js, source:https://eloquentjavascript.net/20_node.html#h_TUzbi7lU/0
I've downloaded the lastest recommended version of nodejs (12.13.0 LTS), made the js file the book tells me to run (I made it in visualstudio because renaming a .txt file with the code to .js didn't do the job) and copy pasted it in the folder where the nodejs folder is, ran the command (ran several others that i thought would work as well) and i get this error:
This other thread had a similar problem with a solution, while it might solve the problem of running the program, it doesn't run it in the way the author of the book im reading tells me to, How to run a hello.js file in Node.js on windows?
Hello and welcome to SO.
You seem to have run node then hello in the node REPL, which is, of course an undefined variable.
Exit out of node and run node hello.js. This will use node to execute the code in the hello.js file if you are in the same folder/directory as it.
Just close this node terminal and start a new command prompt from the desired location and run "node hello.js" in a single line.

issue with node.js not executing properly

Okay so I am really new to server-side scripting but love to give it a try. My issue thus far is that when I attempt to launch a file like "hellonode.js" I cannot.
I launch node and attempt to access a file from within a folder called new
and I get this error:
console is undefined
however when I use node and manually type the address in I get the intended results
the javascript application works completely as intended
I really wanna know why it is I cannot execute Node from within a folder but if I manually go to it each time I can. It is rather frustrating
When you are going to execute a node script the 1st argument to node should be the uri of the script file. so
node path/to/your/nodeScript
path would be absolute or relative to your current working directory.
also you can run a node script by giving only the folder of the node script but you need to create the node script file as index.js
suppose you have a folder name MyFirstNodeScript and inside the folder there is a file named index.js the script would be
console.log('hello world!!!');
now you can run the script by node MyFirstNodeScript but you should be in the parent directory of the MyFirstNodeScript
I'm not sure how you get the error but essentially you just "opened" a .js file in windows, which resulted in windows JScript executing your file instead of node executing your file. Maybe because your node.js file, or do you simple double-click?
Basically if you want a file to double-click to start your server create a short .bat file that contains the working snippet to start your node script. However in reality you usually don't need a thing to double click at all.
I think you need to give the address to the current file in the directory. It's more of a command line way of executing files rather than a node js convention.
node .\hellonode.js
In Unix (Linux or Mac) command lines it should be like this:
node ./hellonode

How can I run a JavaScript automatically on a command-line?

I have a simple JavaScript myScript.js with code as below;
var printer = function(someString){
console.log(someString);
}
printer("This is printed on console.");
I'm on Windows 10 and need to be able to call myScript.js on a command prompt and have the code executed without doing node myScript.js. Is there a way to set up things so that Command prompt or PowerShell can automatically call Nodejs or other JavaScript engine?
If your Windows can run normal shell scripts on the command line then you can add a shebang line to your Node script just like you do with shell scripts. For example:
#!/usr/bin/env node
// your node code here
Also you can try to configure Node to be invoked for all files with the .js extension but this can be a security hazard because you may execute arbitrary code just by clocking on JavaScript files that you may have downloaded on your system so I wouldn't really recommend that.
Another alternative is to make a BAT script for you Node app:
example.bat:
node example.js
example.js:
// your Node script
That you will be able to run with just:
example
on your command line.

How can I run my node script using a shell script file

I am creating a personal site using node. It is going to help me keep track of the ebooks that I am reading.
At the moment, I need to cd to the project folder and run node server.js.
I thought I'd create a shell script and then I'd just have to double click on the file. The file would have the following code:
#!/usr/bin/env bash
node server.js
The first error I've got was that server.js is not found at the root directory, I fixed that by typing the full back, then it threw same error for all the dependencies in the application
(I have never used shell scripting)
Is what I am trying to do possible?
I am assuming you are Linux user.
Set the path in your $HOME/.profile
export MY_COOL_NODE_APP=$HOME/nodejs/app/cool_app
Now your script will run as:
node $MY_COOL_NODE_APP/server.js
So in case if you move your app, you will need to update your .profile

'cocos' is not recognized as an internal or external command in the my project directory

I am very much beginner in cocos2d-js game development, I am learning it past two days. I tried to run the my project through cocos command BUT its showing cocos command is not recognized as internal or external command. I have followed this link to create and run the project http://cocos2d-x.org/docs/manual/framework/html5/v2/cocos-console/en
My project directory is D:\Mallikarjun_Disk\cocosAndroid\cocos2d-js-v3.0\cocos2d-js-v3.0\tools\cocos2d-console\bin\Projects\MySimpleGame
I moved to this directory to run my MySimpleGame in command prompt BUT its throwing error 'cocos' is not recognized as an internal or external command, operable program or batch file.
Please give suggestions what might be the problem.
Giving me a simple steps for running project would be much appreciated
You've most likely:
A. Not ran setup.py from your installation folder.
B. Already ran it, but haven't rebooted your system yet.
(Note that you need to have previously installed Python v2.x, Ant -and possibly CMake- in order for setup and all other commands to work).
If you've already done this and still get the error, make sure in your System's Environment Variables that the path to [your cocos2d-js install folder]\tools\cocos2d-console\bin has been added to your PATH.
It'd also be best if you let your project and cocos2d installation folders in two separate folders with short names and no spaces, for example:
C:\cocos2d-js
C:\cocos2d-projects\MySimpleGame
In cocos2d-x v3.2 for cpp i got same error.. it turned out
i did not run
source /Users/your_user/.profile (so that environment variables are actually updated)
this line is generated after you run setup.py
All steps:
Run setup.py
Run source /Users/your_user/.profile (so that environment variables are actually updated)
Run cocos new mygame -p com.your_company.mygame -l cpp -d /directory_to_your_game
replace cpp with js in above command

Categories

Resources