I have a docker container with nodejs in it. (node:14.11-alpine3.12)
There is cron running, that executes .sh file with the command:
node /home/parsecsv.js;
Whenever cron executes this command, I get an error
'rror: Cannot find module '/home/parsecsv.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:893:15)
...
I am absolutely sure this file exists, even more, when I go to the container shell and run this command (node /home/parsecsv.js) from the command line it works just fine. What can I do about this?
Check permission of the file, you may debug by giving full permission to file.
add this to your docker file and see if still the issue persists.
RUN chmod 777 /home/parsecsv.js
So, what helped me is to copy js file to /root directory instead of /home. And then change path in work.sh to this: node parsecsv.js It seems like when node is running from sh script it cannot read absolute path or something. That's confusing, but now it is working.
Related
I have successfully used nssm to create a node service that runs in the background. I have done this, however, with .js files where you set the path to node.exe, then set the startup directory, then set the .js file you want to run in the arguments. Works great.
I'm trying to get http-server to run in the background, and I can't quite make it happen. The difference is, to run http-server, you don't run node.exe, just the 'http-server' command with a path after it. So, I'm scratching my head as to what I place in nssm for the path, startup directory, and arguments.
I've tried to place http-server "C:\path...etc." into a .bat file and run that with nssm, but when starting the service, I get the "Windows could not start the service on local computer..." error, and the service does not start. I've also tried to convert the .bat to a .exe and run into the same error.
Any help would be greatly appreciated!
I have a little node application on a server (node mailer) that I run by going to its source folder and executing npm start. I figured the best way to run this automatically would be to create a my_script.sh file and drop it in the init.d directory of my debian box. Inside the file (below the !#/bin/bash line), the code to execute is
'/opt/mycode/source/npm start'
I save the line to the .sh file and restarted the machine, but so far haven't got it to work. My question is: is this even how you start a script like this (using that command and an .sh file)? It does start normally when I do it manually (when I navigate to it and run npm start in the terminal). I included the single quotes around it because of the space between npm start. Also, if I want to verify that it worked, which process would I look for other than just pinging my smtp mailer? Finally, I know I need to run:
update-rc.d my_script.sh defaults
but I was also confused at to whether I had done this correctly either (is it just the name of the file that goes there or the file plus the extension)?
The script that you leave on the init.d folder should not have any extension and should have functions to start, stop and get the status of the service (your application).
I'll leave a link with an example as well as with some basis in order to build the Linux service script.
I would suggest reloading the daemon with systemctl daemon-reload in order to refresh the Linux service files once you add a new one.
I am trying to install pumba from the OS release page. Once it is downloaded, I try running
pumba --help
It gives a command not found error.
Can anyone suggest what am I missing? The amd_64 file has all read, write and execute permissions.
If the name of the file is pumba_linux_amd64, you have to use that. Additionally, since the file is (assuming) not in your $PATH, you can't launch it directly.
If your file is in your current directory, run
./pumba_linux_amd64
I need subprocess in my script to connect with 3G. But unfurtunately it's throwing me alot of errors. So I was hoping maybe someone here could help me.
My code:
import subprocess
import time
subprocess.run('sudo ./sakis3g connect OTHER="USBMODEM" USBMODEM="12d1:1001" APN="internet"', shell=True)
When I run this simple script in my home directory I get the following error:
sudo: ./sakis3g: command not found
Is it maybe because the sakis3g script itself it located in /usr/local/bin. Any help would be appreciated, thanks in advance
I run this simple script in my home directory
./ means the current directory i.e. the home directory in this case.
Is it maybe because the sakis3g script itself it located in /usr/local/bin
/usr/local/bin is (likely) not your home directory. sudo can't find sakis3g in the current directory because there is no such file.
Use /usr/local/bin/sakis3g instead of ./sakis3g.
copy that saskis3g object file in your directory where you have your code then you can use the command directly without including any file path for the object file(i.e sakis3g) in your connect command.
if suppose you have a folder named sample. and your program resides in this folder then copy+paste the sakis3g object file to this folder[you can do this by using the CP command in linux ] and use the normal command ie " system("sudo ./sakis3g connect"); " no need of any path.
I'm new to nodeJS and also new to StackOverflow...
I'm starting to develop my first SPA, using RequireJS to compile my sources into a "dist" folder. I had NodeJS running a basic script to run my server:
var connect = require('connect');
connect.createServer(
connect.static(__dirname)
).listen(8080);
Everything was working well, till I compile my src again. That replaced all the files served by my server, so I though I would restart Node. I Ctrl^C and from this moment, I can't get Node to start again. When I try to run:
olivier$ node server.js
I get this error:
node.js:810
var cwd = process.cwd();
^
Error: ENOENT, no such file or directory
at Function.startup.resolveArgv0 (node.js:810:23)
at startup (node.js:58:13)
at node.js:901:3
What's strange is that I get the same error just trying to start NodeJS, simply doing:
olivier$node
Anyone has an idea of what I can do beside uninstalling Node and reinstalling it ?
I got this when trying to run the Node REPL from a directory I had already deleted (from another shell). Don't let this happen to you or you will be ashamed.
Could it be that RequireJS is also recreating the directory that contains your server.js?
Try and see if this works:
$ cd $PWD; node server.js
Although it seems useless to change the directory to the current directory, the rationale is that when a directory gets deleted while it's the current working directory of your shell, the shell is left in a dangling state because it's still 'attached' to the previously deleted directory. This also affects any processes that you start from that shell (like Node), and can yield confusing errors.
By executing cd $PWD, you make sure your shell gets 'reattached' to the newly created version of the directory, solving the dangling state.
use
cd .
is ok.
But the problem is in server
Remove the folder in another terminal and save its the file,
Open the new terminal on folder structure, and run the file.
Folder structure was not available on the current terminal session. When you close it and re-open the terminal in your file directory, the structure will be refreshed.
I faced the same issue.
To Solve this issue enter below command :
cd ..
OR
Check your directory in Terminal/CMD. and Change it.
Actually this issue coming when you deleted your project folder form your PC and without change directory try to run any command of React-Native.
I faced the same kind of a problem when starting the app in cluster mode via pm2.
I did the following & it worked,
* executed pm2 kill
* Removed node_modules
* npm install
* start the application
Reference: https://github.com/Unitech/pm2/issues/1244
Then it started to work as expected. Hope it helps.
If we try to do any actions on an already deleted file from another shell then we'll face this issue.
Just restart the system it'll work normally ( It worked for me )
I would suggest to close all the terminals and run below commands
sudo npm cache clean -f
sudo npm install -g n
and voila: no more process.cwd problems