Node module missing error when script tries to restart - node.js

I am running CentOS Linux release 7.1.1503 (Core) and I frequently run into a problem of missing node modules.
Here are some paths I printed on the console:
which npm
/root/.nvm/versions/node/v8.2.1/bin/npm
which node
/root/.nvm/versions/node/v8.2.1/bin/node
which forever
/usr/local/bin/forever
Now, when I start the script with forever it runs. Sometimes in the midnight, when I just verify if all the scripts are running, many are failing and the error is something like:
I have to go and install the node module. What could possibly be the reason for this? Could it be some permission issue?

Check if you have fs-extra installed at the directory you working or globally (if not - just run npm install fs-extra)
If you are going to work with AWS.S3 - check credentials permissions (for example aws s3 ls - you should see list of available buckets)

Related

Weird PM2 - NodeJS Version Behaviour

I am experiencing a weird bug with NodeJS's File System module, where the remove directory function is asking for a callback, despite there being one. Having a look, it turns out this is a bug with NodeJS that was resolved in later releases
I tried to update the server's nodeJS version, except, as NVM was reporting, it was already fully updated.
Using the pm2 show APP_NAME command, I determined that PM2 was running the app in NodeJS v10.19.0, and all steps to update it were fruitless.
So how can I fix this?
Notable Details:
DigitalOcean Ubuntu 20 Droplet
PM2 Installed
NodeJS v16.15.1
NVM Installed
In order to resolve this issue, I had to kill the current in memory version of PM2, and go to the following directory as root:
~/.nvm/versions/node/v16.15.1/bin in there is a pm2 executable.
In order to get the application to run in Node v16.15.1, I had to run the following command ~/.nvm/versions/node/v16.15.1/bin/pm2 start index.js --name APP_NAME, and then and only then did it run the application properly.

Stop EBS Linux 2 (Node.js) from trying to do npm install?

I'm trying to run a Node application on AWS Linux 2 on Elastic Beanstalk and need to install the dependencies using yarn. (My Node app causes errors if you try to use npm to install dependencies instead of yarn.)
I've already figured out how to set up a script in .platform/hooks/prebuild/ to get it to run yarn, but even though it's running the yarn installation, it still also tries to run npm install, which errors out, causing my deploy to fail.
So I need to figure out how to prevent the default npm install step from running.
(Does anyone know what file that command is run from in the AWS Linux 2 setup process? I was wondering if I could just add another script in .platform/hooks/prebuild/ that would modify that file to prevent the call to npm.)
yes, you can avoid npm install
When you deploy a node_modules directory to an Amazon Linux 2 Node.js platform version, Elastic Beanstalk assumes that you're providing your own dependency packages, and avoids installing dependencies specified in a package.json file.
source doc

Laradock - add custom npm package

It's a kind of not normal thing, but this is something, that temporarily is a solution.
I have laradock installed in a system and laravel app.
All that I'm using from laradock provides me command below
docker-compose up -d nginx mysql php-worker workspace redis
I need to add node package (https://www.npmjs.com/package/tiktok-scraper) installed globally in my docker, so I can get results by executing php code like below
exec('tiktok-scraper user username-n 3 -t json');
This needs to be available for php-fpm and php-worker level, as I need this in jobs and for endpoints, that should invoke scrape.
I know, that I'm doing wrong, but I have tried to install it within workspace like using
docker-compose exec workspace bash
npm i -g tiktok-scraper
and after this it's available in my workspace (I can run for instance tiktok-scraper --help) and it will show me the different options.
But this doesn't solve the issue, as I'm getting nothing by exec('tiktok-scraper user username-n 3 -t json'); in my laravel app.
I'm not so familiar with docker and not sure, in which dockerfile should I put something like
RUN npm i -g tiktok-scraper
Any help will be appreciated
Thanks
To execute the npm package from inside your php-worker you would need to install it in the php-worker container. But for the php exec() to have an effect on your workspace this workspace would need to be in the same container as your php-worker.

How to run asp.net core application using pm2 on linux server

I have updated my asp.net core API over linux server using kestrel, I want to run the core application using pm2. Let me know if any buddy has already done this kind of task.
What I have tried is:
I Installed the pm2 on my linux server (not globally). It installed successfully but when I'm trying to run the code using pm2, I am getting error pm2, command not found
I tried to install the pm2 globally but getting write access issue in node modules some where but I can't give global write access.
Thanks in advance for your help :)
pm2, command not found means the binary is not found cause it is most probably missing in your PATH variable. The path differs whether you install it globally or not - see pm2-command-not-found how to figure out the path and how to add it to your PATH variable.
When not installed globally, the binaries are under ~\node_modules. This you have to add the actual binary path e.g. ~/node_modules/pm2/bin to the PATH variable or you call it directly using ~/node_modules/pm2/bin/pm2
For the installation problem mentioned above, run the installation as sudo npm install -g pm2

Installing npm modules in a VM shared directory and grunt issues

I'm trying to put together a development environment and npm is causing me problems. Here is my scenario:
I have a development machine running Windows and VMWare Player. I have a Ubuntu Server VM (no UI) which is configured with Apache, PHP, NodeJS etc. As the VM has no UI I want to use the host OS for development. I set up a shared directory which in the VM is accessed as /mnt/hgfs/source/<project name>.
The problem comes when I attempt to run npm install within this directory. I see a lot of errors like Error: UNKNOWN, symlink '../requirejs/bin/r.js'. I know that my package.json file is OK because if I copy all files out of the share and into a regular unix directory (/var/www/<project name>) npm install works fine. So npm has a problem installing modules in the shared directory.
I thought I could get around this by installing the node packages globally but, for whatever reason, the GruntJS enthusiasts don't like that and it must be present locally. I then tried to create an npm link from global to local but that just results in a new error: Error: May not delete: /usr/lib/node_modules/grunt. I have full permissions on the /usr/lib/node_modules directory and all sub-directories.
I really don't want to write the entire project using a command-line text editor in the VM but it looks like I cannot have my code-base in a directory available to both the host and guest OS through VMWare.
I would very much appreciate any suggestions on how to either 1) allow npm modules to be installed in my shared directory, 2) run Grunt globally, or 3) solve the npm link error I'm seeing.
EDIT: Shortly after posting this I realised the fundamental issue here - it's not possible to create symbolic links within a VM shared directory when the host OS is Windows. As npm install uses symlinks by default it didn't work, and this is why the accepted solution does work.
Try the following:
npm install --no-bin-links
Grunt should be local since the plugins and gruntfile.js may require a certain version of Grunt in order to run your tasks. If another developer would like to run your tasks, they could just issue an npm install and they are set. (See this for more info.) grunt-cli is global which is used to run the local version of grunt

Resources