Cannot find module 'http-simple-proxy' - although everything is set correctly - node.js

I installed http-simple-proxy globally. I even have it as command in the shell. Then - I created a small JS file with the content from the README (the first section, Installation and basic usage), but when I run it with node {name-of-JS-file} - and it failed with:
$ node {name-of-JS-file}
internal/modules/cjs/loader.js:883
throw err;
^
Error: Cannot find module 'http-simple-proxy'
Require stack:
- {name-of-JS-file}
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> ({name-of-JS-file:3:23)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '{name-of-JS-file' ]
}
I have setup the necessary stuff correctly:
$ node -v
v14.16.0
$ npm -v
7.8.0
$ echo $NODE_PATH
/home/petar/.npm-packages
$ ls -la $NODE_PATH
total 24
drwxr-xr-x 6 petar users 4096 Oct 26 15:19 .
drwxr-xr-x 62 petar users 4096 Apr 21 21:22 ..
drwxr-xr-x 2 petar users 4096 Apr 21 20:56 bin
drwxr-xr-x 2 petar users 4096 Oct 19 2020 etc
drwxr-xr-x 3 petar users 4096 Oct 15 2020 lib
drwxr-xr-x 3 petar users 4096 Oct 26 15:19 share
$ which http-simple-proxy
/home/petar/.npm-packages/bin/http-simple-proxy
$ http-simple-proxy
usage: http-simple-proxy [options]
Starts a http-simple-proxy server using the specified command-line options
options:
--version
--config CONFIGFILE Configuration file (YAML or JSON)
--configloader JS-FILE Provide js file as config loader
--configloader-test Test config configloader by printing out its output
--watch Watch config for changes and automatically reload with zero downtime
--silent Silence the log output
--user USER User to drop privileges to once server socket is bound
--group GROUP Group to drop privileges to once server socket is bound
--show-rules Show all rules upon every config load
-h, --help You're staring at it
See https://github.com/gusnips/http-simple-proxy for further info
Any idea what the issue might be?

I installed http-simple-proxy globally.
Globally installed packages are not available for import/require from Node.js programs. You need to install it locally, or at least in the path to your project. Note that the README say to npm install --save http-simple-proxy and does not say to install it globally. Install it globally to get the executable available to your shell, but not to use in a Node.js program itself.

Related

How can I start Docusaurus as a service on Linux (Ubuntu)

Hi guys I try to start Docusaurus V2 as a service on ubuntu headless. Currently I have a script in my Docusaurus folder as a temporarly solution. It works when I start it with ./start.sh:
/var/www/citro-docs-2/start.sh
#!/bin/bash
npm run serve
I tried to create a service like that:
/etc/systemd/system/docusaurus.service
[Unit]
Description=Docusaurus Service
[Service]
ExecStart=/var/www/citro-docs-2/start.sh
WorkingDirectory=/var/www/citro-docs-2
[Install]
WantedBy=multi-user.target
But when I start it with sudo systemctl start docusaurus.service and check the status I get these errors:
● docusaurus.service - Docusaurus Service
Loaded: loaded (/etc/systemd/system/docusaurus.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2021-08-25 11:53:20 UTC; 4s ago
Process: 3494 ExecStart=/var/www/citro-docs-2/start.sh (code=exited, status=1/FAILURE)
Main PID: 3494 (code=exited, status=1/FAILURE)
Aug 25 11:53:20 citro-docs2 start.sh[3521]: at require (node:internal/modules/cjs/helpers:94:18)
Aug 25 11:53:20 citro-docs2 start.sh[3521]: at Object.<anonymous> (/var/www/citro-docs-2/node_modules/#docusaurus/c>
Aug 25 11:53:20 citro-docs2 start.sh[3521]: at Module._compile (node:internal/modules/cjs/loader:1101:14)
Aug 25 11:53:20 citro-docs2 start.sh[3521]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153>
Aug 25 11:53:20 citro-docs2 start.sh[3521]: at Module.load (node:internal/modules/cjs/loader:981:32)
Aug 25 11:53:20 citro-docs2 start.sh[3521]: at Function.Module._load (node:internal/modules/cjs/loader:822:12)
Aug 25 11:53:20 citro-docs2 start.sh[3521]: at Function.executeUserEntryPoint [as runMain] (node:internal/modules/r>
Aug 25 11:53:20 citro-docs2 start.sh[3521]: at node:internal/main/run_main_module:17:47
Aug 25 11:53:20 citro-docs2 systemd[1]: docusaurus.service: Main process exited, code=exited, status=1/FAILURE
Aug 25 11:53:20 citro-docs2 systemd[1]: docusaurus.service: Failed with result 'exit-code'.
I found a solution where I can start the .js file directly: How do I run a node.js app as a background service? but I don't know if this is also possible for Docusaurus. At least I don't know which .js file I should start. It would be awesome if someone could help.
Yes, it is possible to run Docusaurus as a service on Ubuntu. It's important to mention that what you're trying to do here is quite normal for Node.js apps. After all, if you don't run your Node.js app as a service, then the service would stop running as soon as you close the shell you used to start the app.
However, it seems like most folks don't run Docusaurus on Ubuntu since it's "just a static site" and static sites don't really need a full blown server to run on. For example, you could leverage GitHub Pages to run your docs site.
That being said, Docusaurus is just a Node.js app. It's similar to all other Node.js apps, and you can certainly run it in Ubuntu if you wanted to.
Take a look at the docs on PM2.
The way I would start your app as a service is:
Install Node.js on your Ubuntu server (if it isn't already installed)
Install pm2 globally on your server via npm install -g pm2
Navigate to your app's directory and run npm install to install the dependencies of your app.
Now you can run pm2 start /var/www/citro-docs-2/start.sh --name myDocsSite
Your Docusaurus app should now be running. To stop it, you can run pm2 stop myDocsSite.

Error: EACCES: permission denied, open '/home/myname/.config/insight-nodejs/insight-yo.json.3782504431'

When I am trying to install a meanjs template with yo generator sudo yo meanjs, it gives me this error:
/usr/local/lib/node_modules/yo/node_modules/write-file-atomic/index.js:236
throw err
^
**Error: EACCES: permission denied, open '/home/myname/.config/insight-nodejs/insight-yo.json.1173957578'**
<br> at Object.fs.openSync (fs.js:646:18)
at Function.writeFileSync [as sync] (/usr/local/lib/node_modules/yo/node_modules/write-file-atomic/index.js:212:13)
<br> at Conf.set store [as store] (/usr/local/lib/node_modules/yo/node_modules/conf/index.js:142:19)
at Conf.set (/usr/local/lib/node_modules/yo/node_modules/conf/index.js:64:14)
at Insight.set optOut [as optOut] (/usr/local/lib/node_modules/yo/node_modules/insight/lib/index.js:56:15)
<br>at Object.<anonymous> (/usr/local/lib/node_modules/yo/lib/cli.js:206:18)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
My global nodejs modules is :
'ls -la /usr/local/lib/node_modules total 52'
drwxr-xr-x 13 root root 4096 ديسمب 7 18:01 .
- drwxr-xr-x 5 root root 4096 أكتوب 21 09:53 ..
- drwxr-xr-x 4 nobody ayoub 4096 ديسمب 7 17:54 bower
- drwxr-xr-x 5 nobody ayoub 4096 أكتوب 21 09:59 electron
- drwxr-xr-x 5 nobody ayoub 4096 ديسمب 6 16:42 express-generator
- drwxr-xr-x 19 nobody ayoub 4096 ديسمب 7 18:01 generator-meanjs
- drwxr-xr-x 5 nobody ayoub 4096 نوفمب 8 11:54 grunt
- drwxr-xr-x 6 nobody ayoub 4096 نوفمب 8 11:52 grunt-cli
- drwxr-xr-x 4 nobody ayoub 4096 نوفمب 6 21:15 gulp
- drwxr-xr-x 6 nobody ayoub 4096 نوفمب 8 16:16 gulp-cli
- drwxr-xr-x 5 nobody ayoub 4096 نوفمب 12 14:10 mern-app-generator
- drwxr-xr-x 4 nobody ayoub 4096 نوفمب 8 16:43 yarn
- drwxr-xr-x 4 nobody ayoub 4096 ديسمب 7 17:56 yo
And my operation system is: ubuntu 18.04
It seems like root user cannot access to this file.
Removing sudo before the command walked for me. I mean, just try yo meanjs
could you try this :
sudo npm install -g yo --unsafe-perm=true --allow-root
and then run command to create app
sudo yo meanjs
If still getting error try this:
chown -R $USER $HOME/.npm
sudo chown -R $USER /usr/local/lib/node_modules/yo
sudo yo meanjs
Read more here :
https://github.com/krakenjs/generator-kraken/issues/114#issuecomment-54201366
Ubuntu - nodejs - npm install -g > Error: EACCES: permission denied, mkdir
Try the following command
sudo chown -R $USER:$(id -gn $USER) /home/myname/.config

node.js: Error: Cannot find module './Etherio'

I'm in the middle of updating my node.js code (http://ushomeautomation.com/Projects/node-irrigation/sched.js , code in question is near the top of the file) and this is my first module which is installed via:
npm install --save git+https://git#github.com/linuxha/Etherio.git
The Etherio code is in development too. This works:
var Etherio = require('/home/njc/dev/irrigation/irrnode/node_modules/Etherio');
but this doesn't:
var Etherio = require('./Etherio');
And what I mean by works is that the code runs and the lights lite up on the etherio board (which is what my module talks to).
~/dev/irrigation/irr-sched$ node ./sched.js
module.js:329
throw err;
^
Error: Cannot find module './Etherio'
at Function.Module._resolveFilename (module.js:327:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:355:17)
at require (internal/module.js:13:17)
at Object.<anonymous> (/home/njc/dev/irrigation/irr-sched/sched.js:70:15)
at Module._compile (module.js:399:26)
at Object.Module._extensions..js (module.js:406:10)
at Module.load (module.js:345:32)
at Function.Module._load (module.js:302:12)
at Function.Module.runMain (module.js:431:10)
~/dev/irrigation/irr-sched$ pwd
/home/njc/dev/irrigation/irr-sched
~/dev/irrigation/irr-sched$ ls -la node_modules/Etherio/
total 24
drwxr-xr-x 2 njc njc 4096 Nov 28 19:33 .
drwxr-xr-x 59 njc njc 4096 Nov 28 19:33 ..
-rw-r--r-- 1 njc njc 4183 Nov 28 19:33 Etherio.js
-rw-r--r-- 1 njc njc 2317 Nov 28 19:33 package.json
-rw-r--r-- 1 njc njc 90 Nov 28 19:33 README.md
Am I missing something obvious?
Linux Debian (3.16.36-1+deb8u1 x86_64)
npm (3.3.12)
node (v5.2.0)
Making my comment into an answer since it solved the issue:
This appears to be just a path issue.
I don't quite understand your directory structure, but require('./Etherio'); looks for the module in the same directory as the module whose code is currently running and it looks ONLY in that directory (it does not look in the node_modules directory below.
If Etherio is in node_modules below the current module directory, then just use require('Etherio');

Easyrtc gives socket.io.js file issue for the html of the site

The same question is available on easyrtc forum
https://easyrtc.com/forums/viewthread/167/
I was trying to implement the demo provided here : https://demo.easyrtc.com/demos/demo_audio_video_simple.html
Following steps as given in the below link
https://easyrtc.com/docs/guides/easyrtc_server_install.php
—-
Install Node.js
curl -sL https://deb.nodesource.com/setup | sudo bash -
sudo apt-get install -y nodejs
—-
I am at logged in as root user
root#pbx:/var/www/html#
I did not get any erorr while running above commands
After running the above commands , I went to the second step
——-
2. Create folder hold the EasyRTC application
ex: sudo mkdir /var/nodes
ex: sudo mkdir /var/nodes/easyrtc
—-
I created a folder /var/nodes/easyrtc as given in example
Should I create instead on /var/www/html (where my domain is pointed to)
—-
3. Security Considerations (not going into specifics)
Create user for node.js (or use existing web user)
chown the nodes folder to be owned by this user
ensure the node is run as that user.
—-
Skipping above step since I am already logged in as root.
Please point out how I could verify the three things mentioned above.
———
Download files from the server_example(https://github.com/priologic/easyrtc/tree/master/server_example) folder into your EasyRTC application folder.
OR download and extract this .zip
—-
Does ‘EasyRTC application folder’ mentioned above indicate /var/nodes/easyrtc ?
https://github.com/priologic/easyrtc/tree/master/server_example
root#PBXRecptionist2:/var/nodes/easyrtc# ls
easyrtc-master master.zip package.json README.md server.js static
After downloading the files I get the above in the easyrtc folder
—
Change to the easyrtc folder and then install node modules locally
cd /var/nodes/easyrtc
sudo npm install
—
following the other instructuion
It added node_modules folder with modules as given below
root#PBXRecptionist2:/var/nodes/easyrtc/node_modules# ls
easyrtc express socket.io
—-
Running EasyRTC Server
From Console
Open your console on the server.
In Windows you can use the provided Node.js console program located in the Start Menu.
Navigate to your EasyRTC application folder
Run the server using the node command.
node server.js
—
What does “Open your console on the server.
” mean?
I am logged in via ssh
should I type command “node ” which opens a node console ??
Does “Navigate to your EasyRTC application folder” this mean moving to /var/nodes/easyrtc ?
When I do this “Run the server using the node command.” ,
node.js on /var/nodes/easyrtc
I get the following error
root#PBXRecptionist2:/var/nodes/easyrtc# node server.js
module.js:340
throw err;
^
Error: Cannot find module ‘../’
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object. (/var/nodes/easyrtc/server.js:5:15)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
and if I do it
root#PBXRecptionist2:/var/nodes/easyrtc# node
node server.js
...
I dont get anything
can anybody point where I am going wrong
Also I get an error that” Your HTML has not included the socket.io.js library”
I am unsure how can I locate the socket.io.js library
My index.html for which I get the above error is
ABCTELECOMMUNICATION: Simple Audio and Video Chat
[removed][removed]
[removed][removed]
[removed][removed]
Not yet connected…
Connected users:
<div id=“otherClients”></div>
</div>
<div id=“videos”>
<video autoplay=“autoplay” class=“easyrtcMirror” id=“selfVideo” muted=“muted” volume=“0” ></video>
<div >
<video autoplay=“autoplay” id=“callerVideo”></video>
</div>
<!—each caller video needs to be in it"s own div so it"s close button can be positioned correctly—>
</div>
</div>
files in the same directory as on the index.html are
drwxr-xr-x 7 root root 4.0K Mar 22 09:14 node_modules
-rw-r—r—1 root root 603 Mar 22 09:08 server.js
-rw-r—r—1 root root 1.2K Mar 22 08:49 index.html
drwxr-xr-x 2 root root 4.0K Mar 22 08:44 easyrtc
-rw-r—r—1 root root 1.2K Mar 21 15:23 index.html~
-rw-r—r—1 root root 170 Mar 20 12:02 socket.io.zip
-rw-r—r—1 root root 1.4K Mar 17 09:50 server.crt
-rw-r—r—1 root root 1.2K Mar 17 09:47 server.csr
-rw-r—r—1 root root 1.7K Mar 17 09:31 server.key
-rw-r—r—1 root root 1.8K Mar 17 09:30 server.key.secure
drwxr-xr-x 2 root root 4.0K Feb 21 10:15 js
drwxr-xr-x 2 root root 4.0K Feb 21 10:00 easyrtc-master
-rw-r—r—1 root root 695K Feb 21 10:00 master.zip
drwxr-xr-x 3 root root 4.0K Aug 24 2015 api
drwxr-xr-x 5 root root 4.0K Aug 24 2015 demos
drwxr-xr-x 3 root root 4.0K Aug 24 2015 dev
drwxr-xr-x 4 root root 4.0K Aug 24 2015 docs
-rw-r—r—1 root root 100 Aug 24 2015 index.js
drwxr-xr-x 2 root root 4.0K Aug 24 2015 lib
-rw-r—r—1 root root 1.4K Aug 24 2015 LICENSE
-rw-r—r—1 root root 932 Aug 24 2015 package.json
-rw-r—r—1 root root 5.7K Aug 24 2015 README.md
drwxr-xr-x 3 root root 4.0K Aug 24 2015 server_example
Can someone help me debug and make the easyrtc work?

node.js cannot find app.js after deployment to elastic beanstalk

I've just deployed my application to elastic beanstalk by doing an eb push.
My application isn't starting and the node.js logs say the following:
Error: Cannot find module '/var/app/current/dist/app.js'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
There is definitely an app.js there as evidenced in my putty session
[ec2-user#ip-172-31-12-80 dist]$ pwd
/var/app/current/dist
[ec2-user#ip-172-31-12-80 dist]$ ls -l
total 20
-rw-r--r-- 1 nodejs nodejs 3298 Apr 14 11:43 app.js
drwxr-xr-x 27 nodejs nodejs 4096 Apr 14 11:43 node_modules
-rw-r--r-- 1 nodejs nodejs 858 Apr 14 11:43 package.json
drwxr-xr-x 3 nodejs nodejs 4096 Apr 14 11:43 public
drwxr-xr-x 2 nodejs nodejs 4096 Apr 14 11:43 routes
Anyone know what could be going wrong?
Thanks in advance,
Chris

Resources