Using the Forever Node Module on multiple projects - node.js

I am in the process of setting up two different web application projects on my server. I am attempting to get Node, MongoDB, and the Forever Node module set up correctly so that I can use Forever on my scripts to keep them running 24/7.
The main issue I am running into is the local vs. global installations for Node and the two modules. I have attempted this installation process five times now using a few resources online as well as a bash script that I found here (https://github.com/punkave/stagecoach/blob/master/sc-proxy/install-node-and-mongo-on-ubuntu.bash).
Nothing I do seems to work correctly. Either the Forever command doesn't work from my application's folder or when Forever does work, the process gets stopped immediately with a log file created. Here is the contents of the log file:
module.js:340
throw err;
^
Error: Cannot find module 'mongodb'
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.<anonymous> (/var/www/html/test/requestHandlers.js:6:13)
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 Module.require (module.js:364:17)
error: Forever detected script exited with code: 8
So obviously I am not installing Node, MongoDB, and Forever correctly. What is the best way to go about this process?
I am running on an Ubuntu 14.04 instance hosted on an Amazon AWS EC2 server.
Here is my require() for mongodb:
var mongo = require('mongodb'),
Server = mongo.Server,
Db = mongo.Db,
host = "localhost";
Latest error log that Forever creates:
/var/www/html/test/node_modules/mongodb/lib/mongodb/db.js:403
if(connection && connection.serverCapabilities.hasListCollectionsCommand) {
^
TypeError: Cannot read property 'hasListCollectionsCommand' of undefined
at Db.listCollections (/var/www/html/test/node_modules/mongodb/lib/mongodb/db.js:403:49)
at Db.createCollection (/var/www/html/test/node_modules/mongodb/lib/mongodb/db.js:1026:8)
at Object.<anonymous> (/var/www/html/test/requestHandlers.js:15:4)
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 Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/var/www/html/test/indextest.js:3:23)
error: Forever detected script exited with code: 8

Related

ERR_PACKAGE_PATH_NOT_EXPORTED : Package subpath './dist/pako.es5.js' is not defined by "exports"

I have an issue with the deployment of a node app to production.
When I try to execute with Node a script I get the following error:
internal/modules/cjs/loader.js:498
throw new ERR_PACKAGE_PATH_NOT_EXPORTED(basePath, mappingKey);
^
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './dist/pako.es5.js' is not defined by "exports" in /opt/iul/sat_web_lfr/node_modules/pizzip/node_modules/pako/package.json
at applyExports (internal/modules/cjs/loader.js:498:9)
at resolveExports (internal/modules/cjs/loader.js:514:23)
at Function.Module._findPath (internal/modules/cjs/loader.js:642:31)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1017:27)
at Function.Module._load (internal/modules/cjs/loader.js:899:27)
at Module.require (internal/modules/cjs/loader.js:1090:19)
at require (internal/modules/cjs/helpers.js:75:18)
at Object.<anonymous> (/opt/iul/sat_web_lfr/node_modules/pizzip/js/flate.js:5:12)
at Module._compile (internal/modules/cjs/loader.js:1201:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1221:10)
at Module.load (internal/modules/cjs/loader.js:1050:32)
at Function.Module._load (internal/modules/cjs/loader.js:938:14)
at Module.require (internal/modules/cjs/loader.js:1090:19)
at require (internal/modules/cjs/helpers.js:75:18)
at Object.<anonymous> (/opt/iul/sat_web_lfr/node_modules/pizzip/js/compressions.js:14:19)
at Module._compile (internal/modules/cjs/loader.js:1201:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1221:10)
at Module.load (internal/modules/cjs/loader.js:1050:32)
at Function.Module._load (internal/modules/cjs/loader.js:938:14)
at Module.require (internal/modules/cjs/loader.js:1090:19)
at require (internal/modules/cjs/helpers.js:75:18)
at Object.<anonymous> (/opt/iul/sat_web_lfr/node_modules/pizzip/js/utils.js:7:20) {
code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}
However when I execute this script on the testing server works fine.
We even copy and paste the node modules folder from the testing server to the production server but the error is the same.
I think is an error in some external package but I don't understand how the same configuration can have this kind of error depending on the system.
I've tried to update npm from 6.14.5 to 7.23.0 but the error persists.
Both testing and production server uses the same version of Node, 14.X
The only possibility remaining is that I'm using a different NODE_ENV variable between the 2 servers but looking at the error message it's seems unlikely.
Thanks in advance.

BSON .native is not a function - Node

I'm trying to run my Node Project in Ubuntu 16.04 from AWS. I'm using:
Node v5.8.0
Mongo 3.2.12
Pm2 2.4.1
When I run the project using pm2 or node I get the following error:
ubuntu#ip-172-31-13-71:/var/www/ronteq$ node index.js
/var/www/ronteq/node_modules/mongodb/lib/bulk/ordered.js:15
var bson = new BSON.BSONPure();
^
TypeError: BSON.BSONPure is not a function
at Object.<anonymous> (/var/www/ronteq/node_modules/mongodb/lib/bulk/ordered.js:15:12)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (/var/www/ronteq/node_modules/mongodb/lib/apm.js:7:26)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
Is there something I've to change in my node_modules?
"use strict"
var inherits = require('util').inherits,
f = require('util').format,
EventEmitter = require('events').EventEmitter,
BSON = require('bson').native().BSON, **Error Line**
ReadPreference = require('./read_preference'),
In my local machine everything works fine. I've searched for a solution but nothing, someone has dealt with this error before?

Mongoose: Error cannot find module debug

I'm building a basic MEAN webapp and am new to the stack. I have the front end running, but as soon as I add the following lines to app.js:
var mongoose = require('mongoose');
require('./models/test');
mongoose.connect('mongodb://localhost:3000/design-data-test');
I get the following error in terminal:
Error: Cannot find module 'debug'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/Users/username/node_modules/mongoose/node_modules/mquery/lib/mquery.js:11:13)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
And all of my front end code stops running. Mongodb is running on the default port.
How would I go about resolving this error?
For future visitors: You are probably missing a dependency. Make sure you run this first:
npm install
... before you run your app with npm start or node <app>
I think this may happen if you have a child dependency on debug through another package (for example express or mongoose) but you did not provide the dependencies' package.json files with the deployed application which makes node.js unable to locate debug.

Cannot find module in Nodejs

module.js:340
throw err;
^
Error: Cannot find module './models/todo'
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.<anonymous> (C:\Users\Basel\Desktop\Todo List\routes\api.js:1:74)
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 Module.require (module.js:364:17)
C:\Users\Basel\Desktop\Todo List>
Why this application won't start up? I've already tried a global npm install.
In ./models/todo, the period indicates that node will look in the same folder that api.js is in, which would look for \Todo List\routes\models\todo.js. This does not start from the root of the application. To require this, you'll need to us two periods to jump up a level, and specify the app path as well:
var todo = require('../app/models/todo');
maybe you did not set the system value : NODE_PATH; it should point to your global module location;
in Linux: export NODE_PATH=/usr/local/lib/node_modules/ works good for me;
in my case, the file name i had given in my require statement was wrong. I had my models file named posts.js and i was using require('./models/post'). It worked after i changed it to require ('.models/posts')

Node.js - Module Version Mismatch on Linode Server

I am trying to deploy a node app on Linode (Ubuntu 12.04) while following this guide from Node Knockout: http://blog.nodeknockout.com/post/9300619913/countdown-to-ko-14-deploying-your-node-js-app-to
I have no problems running the server as root, but when trying to start the server as the "deploy" user using sudo start node, I get this error:
/home/deploy/app/source/node_modules/bcrypt/node_modules/bindings/bindings.js:79
throw e
^
Error: Module version mismatch. Expected 11, got 1.
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 bindings (/home/deploy/app/source/node_modules/bcrypt/node_modules/bindings/$
at Object.<anonymous> (/home/deploy/app/source/node_modules/bcrypt/bcrypt.js:1:$
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)
I have tried recompiling bcrypt using make clean then make since I thought my module version was incompatible with my version of node (v0.8.18), but that does not seem to be the case since I can start the server as root with no problem. I feel as though the problem lies in how I set up the deploy user, but I am not sure how to proceed.

Resources