Connect Redis using node JS in Linux - javascript

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

Related

Deploying Strapi to Plesk - strapi not found

I want to deploy strapi to a server managed with plesk.
I installed strapi in cli. Strapi itself also runs there but says that i should visit localhost:1337/admin
In Plesk a startup-file is needed. Strapi suggests a server.js with 2 lines of code in it
const strapi = require('strapi');
strapi(/* {...} */).start();
however, i exactly this. When i hit the NPM install button it also resolves everything without any problem. If i want to reach my site i get a error from Phusion Passenger
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module 'strapi'
Require stack:
- /var/www/vhosts/frosty-goldstine.82-165-106-228.plesk.page/strapi/server.js
- /usr/share/passenger/helper-scripts/node-loader.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at Module.require (/usr/share/passenger/helper-scripts/node-loader.js:80:25)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/var/www/vhosts/frosty-goldstine.82-165-106-228.plesk.page/strapi/server.js:1:16)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/var/www/vhosts/frosty-goldstine.82-165-106-228.plesk.page/strapi/server.js',
'/usr/share/passenger/helper-scripts/node-loader.js'
]
}
How is it possible, that strapi is unknown? And how can i resolve?
Just need to call the good node_module #strapi/strapi instead of strapi
Ubuntu 20.04.4 LTS
Plesk Obsidian
Strapi 4.1.9
npm 6.14.17
node 14.19.3
const strapi = require('#strapi/strapi');
strapi().start();
Make sure you run npm install before trying to start the application.
I don't remember how to do this from the admin interface, but you can SSH into the server and run <path-to-npm>/npm install

Node - Tried to run the file "server.js" through CLI by typing node server.js but it shows message as Cannot find module

Find Visual Studio Code application where I tried to run the file. Things look fine but it says cannot find module. Find my terminal output below along with screenshot in "Node Program"
F:\Git Clone\Node.js_From 31Oct2019\IBM-Developer\Node.js\Course\Unit-6>node server.js
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module 'sqlite3'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (F:\Git Clone\Node.js_From 31Oct2019\IBM-Developer\Node.js\Course\Unit-6\utils\utils.js:23:17)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
Node Program
You have to run npm i and then restart your application and vs code.
Install NPM by typing npm i and then restart your application

NodeJS - why serial reader is failing?

I have installed serialport using npm, but why its failing to connect?
$ ls /dev/tty.*
/dev/tty.Bluetooth-Incoming-Port /dev/tty.usbserial-AI0255BX
$ cat /var/tmp/test.js
var SerialPort = require('serialport');
var port = new SerialPort('/dev/tty.usbserial-AI0255BX', {
baudRate: 57600
});
$ node /var/tmp/test.js
module.js:471
throw err;
^
Error: Cannot find module 'serialport'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/private/var/tmp/test.js:1:80)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
Nodejs search package.json in the same folder as the script. If it does not found it search in the parent folder etc...
I see in your pastbin that you have install the node module in your home, so package.json is unattainable for Node.
You can try this :
npm install -g serialport
The -g (global) option permit to use the bin no matter where you are.
Or :
Move your script in the same folder (or subfolder) where is your package.json

Error: Cannot find module '../build/Release/bson' on Mac

I am using node.js to run one app given by my professor on my chrome. Something wrong happen, but I don't know because I am a rookie.
The structure is as follows:
/app
/models
answers.js
questions.js
sessions.js
user.js
passport.js
qmanage.js
routes.js
/config
auth.js
database.js
mcd.js
package.json
/public
some css png fonts jpg document
qloader.js
server.js
/views
some ejs document
At first, it shows this problem:
module.js:457
throw err;
^
Error: Cannot find module 'mongoose'
at Function.Module._resolveFilename (module.js:455:15)
at Function.Module._load (module.js:403:25)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/shen/Desktop/os/cse303.p2/server.js:2:16)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
then, based on this help Node.js error Error: Cannot find module 'mongoose' I run npm install mongoose in my root path of project. Then I have those error below:
dyn143030:cse shen$ node server.js
{ Error: Cannot find module '../build/Release/bson'
at Function.Module._resolveFilename (module.js:455:15)
at Function.Module._load (module.js:403:25)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/shen/Desktop/os/cse303.p2/node_modules/bson/ext/index.js:15:10)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3) code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version
events.js:160
throw er; // Unhandled 'error' event
^
Error: Invalid mongodb uri. Missing hostname
at muri (/Users/shen/Desktop/os/cse303.p2/node_modules/muri/lib/index.js:40:11)
at NativeConnection.Connection.open (/Users/shen/Desktop/os/cse303.p2/node_modules/mongoose/lib/connection.js:195:16)
at Mongoose.connect (/Users/shen/Desktop/os/cse303.p2/node_modules/mongoose/lib/index.js:212:15)
at Object.<anonymous> (/Users/shen/Desktop/os/cse303.p2/server.js:4:10)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.runMain (module.js:590:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3
I tried to find solution from this help
Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' } js-bson: Failed to load c++ bson extension, using pure JS version
but it seems not my case, because I am using OS X 10.11.3
dyn143030:cse shen$ node -v
v6.5.0
dyn143030:cse shen$ npm -v
3.10.3
From my aspect, I think the system find bson someplace wrong, so how to modify it? Thanks! If any more information is need, please tell me.
I find in node_modules\bson\ext\index.js
and change path on 10th line
bson = require('../build/Release/bson'); to bson = require('bson');
You can try adding mongoose to the dependency list in the package.json file, or also doing >npm install mongoose in the project folder.

Trying to set a hub server for togetherjs application and i am using node.js to run the server i get the following error

Error: Cannot find module 'websocket-server'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:286:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object. (D:\Rahul\hubServer\togetherjs-develop\togetherjs-develop\hub\websocket-compat.js:27:28)
at Module._compile (module.js:434:26)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
That means you have not installed that module. To do this do
npm install websocket-server
Usually instead of doing this manually you will have a package.json file and you can install all the modules by doing npm install
I'd you want to save websocket-server to the package run this command:
npm install websocket-server --save
Remember to do npm install __ in the directory of where your site is. Otherwise node won't find it.

Categories

Resources