Force node.js to use bin/bash instead of sh - javascript

I'm trying to execute a basic bash script from node using the exec() function. The bash script is as follows:
#!/bin/bash
ffmpeg -f concat -i <(for f in $1/*.mov ; do echo "file '$f'"; done) -c copy $1/output.mov
The script works fine running it from the command line but when running from within node I get a syntax error: line 2: syntax error near unexpected token('`
It appears when running this command node it attempting to use sh instead of bash. Can anyone verify this is true and give a possible workaround or solution? Thanks ahead of time!

Try child_process.execFile or just explicitly run ['/bin/bash', '/path/to/your/script.sh', arg1, arg2...].

Provided you're on a recent version of Node, you can add the following as option for exec:
{shell: "/bin/bash"}
See: https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback

Related

"'bun' not found" error in Windows with WSL

First, I run this command on my windows machine
$curl https://bun.sh/install | bash
Output of the above first command
Second, I run this command to set this path in the file
$nano ~/.bashrc
Output of the above second command
After setting these variables into the ~/.bashrc file.
I am trying to check the version of Bun which is just installed, with this command :
$bun --version
After running the above command I got this output :
Command 'bun' not found, did you mean:
command 'ben' from deb ben (0.9.0ubuntu2)
command 'bus' from deb atm-tools (1:2.5.1-4)
command 'zun' from deb python3-zunclient (4.0.0-0ubuntu1)
Try: apt install <deb name>
Can anyone please help me to activate Bun smoothly on my windows machine?
I can tell you that I have successfully installed Bun in Ubuntu 20.04 on WSL2. However, note that it will not currently run in WSL1 (from the Unix & Linux Stack). That's not the error you are seeing here, however.
Apologies in advance if this is not the case, but given that you are new here, I'm going to make an assumption that it might be something very basic that is causing the error you are seeing. The output of the first command indicates that Bun was installed properly, so if it's not found, it seems most likely that you missed one crucial step. You also didn't state that you did it, so ...
~/.bashrc is a file that is typically only read when you start Bash. After adding the variables to your ~/.bashrc, to have it actually set the variables in a shell session, you need to either:
source ~/.bashrc`
Or simply start a new shell (exit WSL and restart, or just run another bash inside bash, etc.
Of course, after doing this, you'll still need to be running WSL2, or you'll run into the other error.
Note that, beyond simply creating a project, I have not tested Bun extensively in WSL2. The Fireship-guy on YouTube did mention that he had some challenges in getting it to run under WSL, but I'm not sure what those were.
I've present the same problem.
Context sotware=> I use win 11 and I've download ubuntu
microsoft store
For this, I enable in feactures
windows turn on and off feactures
and clink here these options
For download bun 0.1.8
I've execute this command
curl -fsSL https://bun.sh/install | bash
late, at the console say that i have to put 2 line of code in a file in my case are :
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"
When, I tried execute bun --version the console showed that did't find bun.
I restart the windows and it seems to have worked
I found answers in the post https://stackoverflow.com/a/73097326/5072481 add username path to $HOME/ is the point

Execute Javascript using Node in terminal

I know that
Node.js allows to write JavaScript code that runs directly in a
computer process itself instead of in a browser
Reading this, I try to open my terminal and run:
console.log('hello')
but I get zsh: unknown file attribute.
The same happens with node console.log('hello').
If I instead create a file hello.js and put the console inside it and then I run:
node src/hello.js
it works. Why? What am I missing?
Sorry for the (maybe) stupid question
It's because the console.log('hello') is being evaluated by your shell (zsh) before running the command and it has no idea what console.log('hello') is. You could use the -e or --eval arguments.
$ node -e "console.log('hello')"
If your using linux, first type node It will profile for you a REPL. which is essecially the excution terminal.
You can also do the same on windows

node.js "Command not found"

I am attempting to work with node and learning how to write in Javascript. I am currently trying to use my terminal to run a basic "Hello world" js file using node. However, when I attempt to use $node index.js (that's what the file is called). All the terminal responds with is index.js command not found. I tried to do it with the just the terminal window, I have also tried to run it through the integrated terminal within data studio, so I am unsure of where I went wrong.
Here is a screen shot of my window.
Remove the $ sign. In web examples, docs use $ to show that you run it in the command line.
Instead use node index.js, or set up a package.json file and use npm start (npm start should contain node index.js).
Final Clarification (if you didn't understand the above explanation)
Run node index.js. $ is never used, except to show you that the command is used in the command line.

Issue with node module timestampnotes "command not found"

I am attempting to use an npm module named timestamp notes.
I have run the following
$npm install timestampnotes
$timestamp
and I get
timestamp:126: command not found: slk
i then tried opening a node repl
$node
>var timestamp = require('timestampnotes');
>timestamp()
and I get basically the same thing, any ideas?
I came across a similar problem. If you are running with zsh on your terminal as opposed to bash, you need to set your 'Shells open with:' option in the Preferences>General to Command (complete path) and set the path to /bin/zsh terminal Command
The same needs to be done if you are running iTerm in place of your default Terminal. You can find this also in your Preferences>Profiles>General and again set Command to /bin/zsh iTerm Command

Install Node.js

I'm completely new to node.js. By reading the documentation and tutorials, I managed to download and install node.js on my windows.
How do I test it and make it work?
The file test.js is saved in the same directory as node.exe and contains:
console.log('Hello World');
Openning the command-line I typed:
$ node test.js
But nothing hapenns, just:
...
You are typing node test.js in the Node REPL not the command line. The ... is indicating that you haven't reached the end of a valid statement yet (because you are writing shell and not JavaScript).
Run a command line with your terminal emulator of choice (probably Windows Powershell if you are using Windows).
Run the Node REPL by executing node via the command-line without any arguments. The reason you're not getting the expected results is probably because you're running node.exe directly. Since you're using windows, start up CMD and run node.exe from there. Once you have the REPL running, try node test.js again, and this time it will work.
![enter image description here][1]I have run it in nodejs shell and it is simply working
> console.log('Hello World');
Hello World
undefined
>
Also I opened nodejs command prompt not default command prompt of windows and then
node path_to_file
it is working... same output

Categories

Resources