How to check which user Phusion Passenger chooses to run node.js? - node.js

What is the best practice for using Phusion Passenger with a version of node installed my nvm?
In this tutorial on using Passenger to run a Meteor app, I read:
[Y]our Meteor application is run as ... the owner of the
main.js file (when deploying a Meteor bundle), unless you configure it
otherwise. Of course you still have to make sure that each of your
applications is owned by another user.
Meteor 1.6 works with Node.js v8.8.1, so I have used nvm to install node. I created a special meteor user to run the nvm installation of node and nvm. Node was therefore installed at /home/meteor/.nvm/versions/node/v8.8.1/bin/node, and /home/meteor/.nvm/versions/node/v8.8.1/bin/ was added to the $PATH variable for my meteor user. As a result, calling node -v as the meteor user showed that v8.8.1 was installed and accessible.
I followed this tutorial to deploy my Meteor app to my server.
As the meteor user from within the bundle/programs/server directory, I ran npm install --production. I made meteor the owner of everthing inside bundle/.
I had expected that Passenger would launch node as the meteor user, and that everything would run smoothly. Instead, Passenger showed a useful alert page, apologising that "something went wrong".
To work around this, I created a symlink at /usr/bin/node to point at /home/meteor/.nvm/versions/node/v8.8.1/bin/node, and now Passenger was happy to launch the bundled app.
This suggests to me that Passenger was not running main.js as the meteor user. Or is there another reason why the meteor user was not able to see its own version of node?
The quote above suggests that it is possible to configure which user Passenger uses. How do I do that?
In a nutshell: what is the official Passenger method for working with a version of node installed by nvm?

You'll want to set the version of node to the full path to the nvm node: https://www.phusionpassenger.com/library/config/standalone/reference/#--nodejs-nodejs
As for the user-switching, you can set the log-level to 7 (https://www.phusionpassenger.com/library/config/standalone/reference/#--log-level-log_level) in order to debug that and either go through the startup logs yourself or post them here.

Related

Weird PM2 - NodeJS Version Behaviour

I am experiencing a weird bug with NodeJS's File System module, where the remove directory function is asking for a callback, despite there being one. Having a look, it turns out this is a bug with NodeJS that was resolved in later releases
I tried to update the server's nodeJS version, except, as NVM was reporting, it was already fully updated.
Using the pm2 show APP_NAME command, I determined that PM2 was running the app in NodeJS v10.19.0, and all steps to update it were fruitless.
So how can I fix this?
Notable Details:
DigitalOcean Ubuntu 20 Droplet
PM2 Installed
NodeJS v16.15.1
NVM Installed
In order to resolve this issue, I had to kill the current in memory version of PM2, and go to the following directory as root:
~/.nvm/versions/node/v16.15.1/bin in there is a pm2 executable.
In order to get the application to run in Node v16.15.1, I had to run the following command ~/.nvm/versions/node/v16.15.1/bin/pm2 start index.js --name APP_NAME, and then and only then did it run the application properly.

Running Vue JS project in Docker

I have already built a few VueJs applications for myself. Now I am working with a team. One backend and me frontend.
Now I'm wondering how do I include the environment in the repository. Until today I always had node on my local machine. With nvm I could also jump between versions on the local machine. But now I want future colleagues who will develop the app to have the same environment. So work with the same node and npm version. I thought this could be done with a dockerfile or docker-compose.yml. Then I can log into the container and run the npm run build for example.
Question But how does it work with npm run dev? Do I have access with the browser to the port that is assigned in the container of the Vue app?

Install React JS on Cent OS

I am very very new to React JS and have tried to install it on my VPS server that is running Cent OS.
Node.js seems to be working,
I have build a React project using the following code as a root level user on SSH:
npx create-react-app my-react-project
cd my-react-project
npm start
but when trying to view in browser I get a blank page (instead of react js default template)?
I see many people install this locally but I haven't found any examples on a hosted VPS, is this something I am doing wrong?
Any help would be much appreciated, thanks!
if you have ssh access to your VPS, the rest is pretty the same as your local environment.
You can copy/paste your project to your CentOS host and use the following commands in order to run it:
cd your_project_folder_which_includes_package_json_file
npm install
npm start
Also, if you are using this server as a production host, You should consider getting a production build of your React app on your local env by running npm run build and then publishing the build folder on your server and serving it using a static file server or using a reverse-proxy such as Nginx as a static server.
Actually this page in React documentation does a good job in explaining the details of deploying a React app, I encourage you to take a look at it.

Issues with installing nodeJS on a shared hosting plan

Here are the steps I am following:
First, I login to my account using SSH.
Then, I install nvm using
wget -qO- https://cdn.rawgit.com/creationix/nvm/master/install.sh | bash
Then, I restart the shell
Then, I install node using
nvm install stable
But, when I check for the version of the node using the following, it says 'command not found'
node --version
If it helps, here are other things I tried:
nvm list
Also, here are the contents of the .nvm folder (which is inside the root folder):
I suppose N/A indicates that node is not available.
To sum it up, is it possible at all to use node.js on a shared hosting plan? If, yes, what can I do to make it work?
PS: I have been getting suggestions to use other plans like Heroku etc. Although, I have already invested a lot in this shared hosting plan (on GoDaddy), so I would really like if I can host nodeJS applications here.
PPS: I am new to programming, so please bear with any ignorance.
Try installing node like this
nvm install node
Then, crucially
nvm alias default node
Now running
node -v
Should display correctly
First of all shared server wont allow you to install anything on their server.
If you can able to install node on your shared server then you are pretty lucky.
To run node --version command, the node command should be in your path. On shared server, it might not be allowed.
So I think you need to check with full path like `/usr/bin/node --version'
(check your installation path)

How can I install nodejs modules to appfog

Normally in local, I use cmd, command line to install any nodejs module using "npm install testing or connect or etc.."
But I decided to use appfog as server and I add nodejs to my project on appfg but probably I am gonna need some nodejs modules like testing, connect, request etc..
The problem is I couldnt found tool like cmd on appfog or any way to add nodejs modules.
How can I do this?
Basically, you just need to install the dependencies in your local environment and everything should be just fine. Simply specify all of your dependencies in your package.json file, run a typical npm install, and if the modules are properly installed in your local environment then they will be pushed to AppFog when you run af update.
You just have to develop your application on your local machine with all the required dependencies in the json package and modules in the Node.JS. And if your application is working properly at that time on your local machine then you can push all that application data to the AppFog using command line interface. Simply use the command af update <your app name> Then start the application and you will see that everything is working properly.

Resources