Node.js Issue w/ Engine.io - node.js

I'm having an issue with my server-side node script from processing. I have a VPS and running node app.js works perfectly fine in my other virtual folder for website1. But when i run node app.js in my website2 virtual folder it says
/home/website2/node_modules/engine.io/node_modules/uws/uws.js:3
const http = require('http');
^^^^^
SyntaxError: Use of const in strict mode.
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 Server.init
(/home/website2/node_modules/engine.io/lib/server.js:115:16)
at new Server
(/home/website2/node_modules/engine.io/lib/server.js:65:8)
at Function.attach
(/home/website2/node_modules/engine.io/lib/engine.io.js:123:16)
at Server.initEngine
(/home/website2/node_modules/socket.io/lib/index.js:274:21)
First, I'll
cd /home/website2
Then I'll
node app.js
Which shows me the error above, but when I
cd /home/website1
Then
node app.js
My script executes. What's the difference? I checked my node version and its 0.10.30, but it works in my website1 home directory regardless. How can I fix this?

Related

How to resolve Sourcetree node path issues after nvm setup?

Sourcetree starting throwing error as below after having nvm setup with multiple versions of node. Sourcetree unable to find the exact nodepath.
How to set default nodePath to target for Sourcetree?
Info: can't find node in PATH, trying to find a node binary on your system
/Users/project-ui/node_modules/husky/run.js:8
message(requiredVersion) {
^
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 Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:929:3
Completed successfully
I managed with couple of steps
which node: /Users/xyz/.nvm/versions/node/v12.18.2/bin/node
I included that to path variable inside bash_profile:
export PATH="/Users/xyz/.nvm/versions/node/v12.18.2/bin:$PATH"
Worked like charm

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.

How to use node-oracle with iisnode?

I'm having trouble trying to run a Node.js server with node-oracle via iisnode. The iisnode examples all work, and running the server [on a different port] in a Command Window works perfectly. The server setup is based upon "The Node Beginner Book" example (i.e. index.njs -> server.njs -> router.njs -> requesthandlers.njs). I renamed all of my node files as *.njs and currently have my web.config set up for iisnode to handle all files of that extension, with a rewrite rule to forward the incoming requests to index.njs. The problem occurs when node-oracle -- utilized within requesthandlers.njs -- attempts to call oracle_bindings.node:
Application has thrown an uncaught exception and is terminated:
Error: The specified module could not be found.
c:\Program Files\iisnode\www\Reports\node_modules\oracle\build\Release\oracle_bindings.node
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> (c:\Program Files\iisnode\www\Reports\node_modules\oracle\lib\oracle.njs:2:16)
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)
I've given read/write/execute permissions to the IIS_IUSRS group on every folder imaginable within the .\iisnode\www\Reports\node_modules\oracle path. I've also attempted the solution in Node cannot find modules in IIS, can find from prompt to no avail. While I could probably just set the server up as a service, I'd prefer to have it through IIS so that I don't have to battle with CORS while supporting IE9. Any help is greatly appreciated, thanks!

Using the Forever Node Module on multiple projects

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

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