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
Related
Hi, right now I'm writing an electron program in which I execute a powershell file with:
sudo.exec('Powershell.exe -Command "D:\Directory\...\file.ps1"');
but since this will only work on my device I want to make the directory dynamic
like this:
sudo.exec('Powershell.exe -Command "../file.ps1"');
but for that to work I would need to know in which directory the cmd/powershell starts initially
or rather how I get it to start in the directory where the javascript file which runs this
is located (the file.ps1 isn't in this directory, but it would be easy to navigate from there)
Thx in advance
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
I am trying to deploy a small Node.js application to Heroku, and then have the Heroku Scheduler run the application every 10 minutes. Our customers former supplier who built this application also hosted it on Heroku, so there should be no need to change anything in the sourcecode, that I have received. Nevertheless I am getting the following error from the Heroku log.
2018-05-09T07:26:07.710882+00:00 app[api]: Starting process with command `fetch` by user scheduler#addons.heroku.com
2018-05-09T07:26:11.124833+00:00 heroku[scheduler.2653]: Starting process with command `fetch`
2018-05-09T07:26:11.718182+00:00 heroku[scheduler.2653]: State changed from starting to up
2018-05-09T07:26:13.647479+00:00 heroku[scheduler.2653]: State changed from up to complete
2018-05-09T07:26:13.629258+00:00 heroku[scheduler.2653]: Process exited with status 126
2018-05-09T07:26:13.542885+00:00 app[scheduler.2653]: bash: /app/bin/fetch: /usr/local/bin/node: bad interpreter: No such file or directory
Apparently there's an issue with the 'Shebang' line in my fetch file which runs my index.js file:
#!/usr/local/bin/node
var path = require('path');
require(path.join(__dirname, '../index')).start();
I am rather new to Node.js and Javascript, so I'm not sure I fully understand the purpose of the 'Shebang' line. But I'm guessing it is pointing to a wrong location or something like that? How do I figure out, what to change in this line?
Shebang line tells which interpreter to use to run the file. Error you receive tells that node is not installed in location shebang points to. Using #!/usr/bin/env node usually works.
You should not have a need for any "shebang" line in your "fetch" file.
I suggest you simply remove the #!/usr/local/bin/node line, and specify the following as your Heroku Scheduler command:
node <path_to_fetch.js>
That should get heroku scheduler to launch your node.js app in a one-off dyno, provided you have a node.js buildpack in your app.
Use the instructions here to check if you have a node.js buildpack in your app, and to add it if necessary.
That said, if you really want to run your app with a "shebang", change it to #!/usr/bin/env node. In that case, omit the word node in your Heroku scheduler command.
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
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