nodejs cmd dynamic directory navigation with sudo extension - javascript

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

Related

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 to run this Go application locally?

I want to be able to run the application from the repository https://github.com/jbowens/codenames locally on my machine. Is it possible?
Steps I've tried:
Installed Go. Added PATH variable.
Cloned the repository to my machine in the right go path location.
Opened command prompt and ran the command "go run main.go" from the "cmd" folder
I really don't know anything about Go so maybe I just have to run another command or install dependencies or whatever. If someone could figure this out I would be super happy! This is an awesome game I would like to play from my machine.
I'm guessing you are just typing go build from the cmd/codenames directory, creating a binary called 'codenames' in that directory and running from there.
Unfortunately the app is hard-coded to look for its assets in a ./assets/ directory relative to the binary.
So you want your binary in the root of the app:
i.e
from the cmd/codenames directory go build -o ../../run-me-from-here
then from the root of the app ./run-me-from-here
.
Running them locally is very easy in go
I usually run go get while in my local go directory.
Go get https://github.com/jbowens/codenames
Set gopath and goroot then install dependencies.

Starting a nodejs http-server using a BAT file when the directory name contains a space

I have a .bat file on windows, which i want to be able to copy to any new folder and doubleclick to start a http server. It only contains one line which is:
http-server %~dp0
The %~dp0picks up the full path to whatever directory the .bat file is currently in. Credit to this answer for that.
It works well when none of the folders in the file path contain a space.
How can i modify the batch file to account for situations where some directories in the path contain a space in the name?
cheers
PS: Im new to this :)
It turns out removing the %~dp0 and just having http-server and nothing else in the batch file makes it work!
It then serves up whatever is in the current directory as shown:

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

Running EXE from Firefox - in a certain path

I found the solution to run an executable file (.bat or .exe) from a local html page in Firefox - it is documented very well here
However, I need to start the executable in the folder where it is located. My executable is a .bat file (D:\Test\file.bat) and it contains the command:
echo %cd%
When I run it, it prints:
C:\Programs\FirefoxPortableLegacy36
instead of printing
D:\Test
Is there any way to specify in the htm/javascript where exactly (in which directory) to start my executable?
thanks.
So you want to make the working directory set to the directory where your batch script is? If this is the case then just add this line right in the beginning of your batch script:
pushd "%~dp0"
You can also read the commandline help for the for command. It explains the parameter replacement well.

Categories

Resources