Cannot start Node.js: permission denied - javascript

I'm running Node.js server on Ubuntu 12.04. When I try to start server with node server.js I get
fs.js:438
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
^
Error: EACCES, permission denied '/home/scadge/nodejs/server.js'
at Object.fs.openSync (fs.js:438:18)
at Object.fs.readFileSync (fs.js:289:15)
at Object.Module._extensions..js (module.js:473:44)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
I also tried sudo node server.js and sudo su followed by node server.js - in all cases I get the same error.

Try as below.
Its permission issue.
Open terminal
Go the project directory.
run chmod -R 777
On everything that is related with access denied can be fix with this.
Thank You.

Related

Unexpected Token '.' on raspberry pi even though script runs fine on windows

I am encountering an error when I go to start one of my Discord bots on my Raspberry Pi 3B.
/home/pi/Downloads/xx/xx/bot.js:301
if (channel?.messages.cache.has(packet.d.message_id)) return;
^
SyntaxError: Unexpected token '.'
at wrapSafe (internal/modules/cjs/loader.js:915:16)
at Module._compile (internal/modules/cjs/loader.js:963:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
at internal/main/run_main_module.js:17:47
When running the same bot on my main Windows 11 Machine, it runs perfectly fine.
NodeJS/NPM on both my main machine and my R-Pi are running v16.15.1. Is there any way I could fix this? Thank you in advance.
As mentioned on the nodejs.org website, you can install the latest versions with the NodeSource deb package:
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
# and then
sudo apt-get install -y nodejs
The default packages on your system are not up-to-date.
Good day

Cannot find module './routes/viewInprogressDetails' ( node app with docker )

I have created docker image for the node application, which is working fine when i run before creating docker image.
my docker file contains:
FROM node:7
WORKDIR /app
COPY package.json /app
RUN npm install
COPY . /app
CMD node app.js
EXPOSE 3000
Step 1:
$ docker build -t myapp .
Step 2:
$ docker run -p 3000:3000 myapp
when i run the above command Im facing below error:
$ docker run -p 3000:3000 kpnv7
module.js:472
throw err;
^
Error: Cannot find module './routes/viewInprogressDetails'
at Function.Module._resolveFilename (module.js:470:15)
at Function.Module._load (module.js:418:25)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/app/app.js:16:29)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)
at bootstrap_node.js:542:3
Not sure where im doing wrong, same application running fine when i give node app.js without errors :(
Thanks in advance :)

Verifying deploy failed: "SyntaxError: Unexpected" while Mup builds to NGINX?

Trying to build a meteor app through mup to the digitalOceans droplet, which runs on Nginx.
During this process, I always stack on deployment verifictation.
nodejs & node version: v4.8.4
npm version: 2.15.11
Error:
x Verifying Deployment: FAILED
-----------------------------------STDERR-----------------------------------
WARN package.json meteor-dev-bundle#0.0.0 No description
npm WARN package.json meteor-dev-bundle#0.0.0 No repository field.
npm WARN package.json meteor-dev-bundle#0.0.0 No README data
npm WARN cannot run in wd meteor-dev-bundle#0.0.0 node npm-rebuild.js (wd=/bundle/bundle/programs/server)
=> Starting meteor app on port:80
/bundle/bundle/programs/server/mini-files.js:82
const unicodeNormalizePath = (path) => {
^
SyntaxError: Unexpected token >
at Module._compile (module.js:439:25)
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 Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/bundle/bundle/programs/server/boot.js:9:13)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
=> Redeploying previous version of the app
-----------------------------------STDOUT-----------------------------------
To see more logs type 'mup logs --tail=100'
----------------------------------------------------------------------------
And here is logs:https://pastebin.com/zs8FG86V
Thank you!
Fixed it, by changing docker image, from 'kadirahq/meteord' to 'abernix/meteord:base' in mup.js file.

'Invalid flags supplied to RegExp constructor' error when running node server.js for Azure IoT Hub

I am trying to run 'node server.js' to connect my raspberry pi device to Azure via the Azure IoT Hub. When I run the command 'node server.js', I receive the following error. Please note that I replaced my computer's user name with 'username'. The file connection_string.js does not have my computer's username in it, despite the error saying that it does. Please see error below:
SyntaxError: Invalid flags supplied to RegExp constructor '*username*'
at new RegExp (native)
at Object.<anonymous> (/Users/*username*/iot-hub-c-raspberrypi-getstartedkit/command_center_node/node_modules/azure-iot-common/lib/connection_string.js:9:31)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/Users/*username*/iot-hub-c-raspberrypi-getstartedkit/command_center_node/node_modules/azure-iot-common/common.js:15:21)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/Users/*username*/iot-hub-c-raspberrypi-getstartedkit/command_center_node/server.js:7:15)
Thank you in advance for your help!
Not sure if it is your case or not, but I had similar issue:
SyntaxError: Invalid flags supplied to RegExp constructor 'u'
I fixed it simply by updating Node.js.
Previous version was:
$ node -v
v5.1.1
Then I did:
$ curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
... long output
$ sudo apt-get install -y nodejs
... shorter output
$ node -v
v6.7.0
And no more issues.

Connect Redis using node JS in Linux

I am trying to connect to redis in linux using node js as below
var redis = require('redis');
But, getting the error as below.
I have redis-2.4.17 installed in linux and the path is /home/masadmin/redis-2.4.17/src
Kindly help on how to connect to redis using node in linux.
module.js:340
throw err;
^
Error: Cannot find module 'redis'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object.<anonymous> (/home/masadmin/Vinod/prapprRedisLoad.js:2:13)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:492:10)
Have you installed the Node.js Redis module for your application? npm install redis (in the same directory as your application) will install it. Check out this screencast for more information.
I have the same error after Node.js Redis module has been installed.
I've fixed it (error) after changing NODE_PATH environment variable:
export NODE_PATH=$NODE_PATH:<YOUR_NODE.JS_HOME>/node_modules

Categories

Resources