How to start server by my source code (app.js) using FTP? - node.js

I'm new to develop server. I already coded my server app.js with Node js and I tested it locally and successfully.
The way I tested my server is that after executing the terminal, moving to the directory having app.js file, command app.js. So then my server is alive and I could test what I want to.
But it's my first time to use FTP to make my server globally. By FTP, I don't know how to do 'node app.js' command.
And if it's done, I don't know the path to test my GET, POST methods.

Related

Is there a command that allows you to restart a pm2 app if a file in another directory is changed?

I have an Ubuntu server that is running plesk obsidian to manage my websites, on the same server I have a nodejs application running with pm2.
There is a json file that a website and the application needs to access. I am able to make the app's code point to the file and access it, but when the website makes changes to the file it doesn't automatically restart the nodejs app as the file isn't in the same directory.
Is there a command that I can use to make pm2 check for changes with the json file and restart the app?
yes there is a command
pm2 start app.js --watch
here app.js is the file name which cause pm2 to restart

Run pm2 commands on the server using execa (nodejs)

The task is to write a utility for deploying the NodeJS application. Requirement is to run the utility from any computer. The problem is that pm2 does not take in mind that I have switched the working directory to the server:
process.chdir ('SERVER');
process.cwd (); // SERVER
But commands run on my workstation. Share furioku, how to let pm2 know that commands need to be run on the server?

PM2 not showing Express app in browser

I am using PM2 in my Express app for process management and load balancing. I have just installed the PM2 and given the command pm2 start bin/www
this command works in command prompt, it is showing the result like this:
This is fine now I am opening the web browser and accessing the application as usual localhost:3000 but it is not opening the application its is showing ok in the browser.
What could be the possible reason? Please help. Thanks.
I got the solution. We know when we create an app using Express (Express generator) it creates all the folder and places app.js file in the root folder. For some reason, I kept the app.js file inside a folder and changed its path in bin/www file. It was working perfectly when I was running npm start but with PM2 it was now opening the application in the browser. So I again placed the app.js file in the root folder and now it is working fine.

Programmatically watch and restart node server

I was getting tired of using FileZilla every time I wanted to push a change to my server hosting my website and so I set up a github repo and linked it to my server so that changes and pushed right to the server.
However, my backend is written in node and so each time I update my server.js file I have to restart the server. With "node server.js"
Is there a way to watch the file and programmatically restart the node server when an update is detected?
If it helps, my serve is Ubuntu Linux running apache2
You could try writing something yourself, or use one of the popular libraries that are already out there:
https://github.com/petruisfan/node-supervisor supervisor server.js
https://github.com/remy/nodemon nodemon server.js

Combine Yeoman Server and Node Supervisor

I'm using Yeoman to develop the frontend html app (backbone and bootstrap) and would like to use the same folder for backend development for the api (node, express, mongodb).
What I would like to do is to have the browser refreshed no matter what file was changed on frontend or backend.
What I'm doing now is:
For Yeoman I'm using the "yeoman server" that would refresh the browser every time I change something in the app folder.
I'm using the node supervisor module and executing the "supervisor server.js" for automatically kill the server and relaunch the node server if file is changed on the backend.
I'd like to avoid this as I need to run the yeoman and node server on different ports.
Is there a way to force autoreload of the browser with node supervisor or use the yeoman server as a classic node server?
You should be able to force the browser to reload with command grunt reload. Just childProcess.exec or childProcess.spawn the command.

Resources