Laradock - add custom npm package - node.js

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.

Related

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

Node module missing error when script tries to restart

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)

Jenkins cannot run npm or pm2 by itself

So I have a Jenkins CI setup on an EC2 server. I have nodejs and npm installed. Weirdly, Jenkins can access them via the command line if I do something like:
sudo -u jenkins node -v
However, Jenkins cannot access them inside an actual build runtime, and I get the following errors:
npm: command not found
pm2: command not found
npm is definitely installed, and ec2-user/root users can access it. What PATH do I have to change so that Jenkins can access it too?
I think that if you use the nodejs plugin it will be easier to manage your node and npm in this box. Also, this plugin allows installing some global modules that possibly you will need to build your project:
https://wiki.jenkins-ci.org/display/JENKINS/NodeJS+Plugin

Running node apps with CodeDeploy

I am using Codeship as my CI tool, I integrate it with AWS CodeDeploy service. The procedure is perfect until my appspec.yml file calls my script to run the node app. Even though I have npm, node, bower and grunt installed I get command not found errors.
I would try editing your start_server.sh and adding npm and node to the $PATH environment variable or put that path directly in the command itself.
So instead of
npm install
Try
/usr/local/bin/npm install
That might not be where your npm lives but if you need to find out just do which npm
Perform the below steps:
which node
sudo ln -s /home/ubuntu/.nvm/versions/node/v12.13.1/bin/node (output of above step) /usr/bin/node
which npm
sudo ln -s /home/ubuntu/.nvm/versions/node/v12.13.1/bin/npm (output of above step) /usr/bin/npm
and try to use it via /usr/bin/npm install
I hope this will help you!!
For people who still might run into the same problem.
Check your appspec.yml file and look at the destination, it should contain something like /home/ec2-user....
in this case we need to make sure code deploy agent runs with that user profile (ec2-user). Check this link for steps to to make code deploy to run with your user profile

I can not use grunt -cli and grunt serve in my web hosting

I have developed a website on Node.js that runs perfectly on my local machine. I run my server with the command:
$ grunt serve
The problem is when i run my web application on my server online ( gandi server ). I can't use the command
$ grunt serve
Because i should install the package '' grunt-cli ''wich :
$ npm install -g grunt-cli
On server Gandi.net, i can't install global package, then i don't use the command
$ grunt
I try a program like
var grunt = require('grunt');
grunt.task.run("serve");
Program don't run.
I need help for run my grunt task '' serve '' without grunt -cli
Option 0
grunt is a build tool and is generally not used to run servers other than local test servers. So the best solution is probably to get your server up and running using pm2 or forever or something else instead of grunt.
As far as getting grunt running on the server, if you still need to do that, you have a few options.
Option 1 is the least disruptive to the system but may require the most understanding on your part to pull off successfully. Specifically, I'm not sure how much grief you will get from grunt if it finds itself in a non-global path.
Note that Option 1 doesn't require superuser privileges.
Option 1
From a shell in your home directory, you can install grunt-cli in without the -g. Then use a shell alias or your PATH environment variable so that you run grunt from ~/node_modules/.bin/grunt.
Option 2
If you have superuser privileges, change the permissions on the global node_modules directory so that you have write access to it.
Some people recommend this over the next option for security reasons, but I think most people probably just go right to...
Option 3
If you have permission to do so on your server, you can use sudo npm install -g grunt-cli.
Option 3 is the easiest but also requires the most trust in the packages that you are installing. Because a package can do anything once you start installing it with sudo, only use this option on packages you inspect and/or trust.

Resources