How to stop a NodeJs file on Ubuntu server - javascript

I paid someone to install a Js script on my server
but when i tried making some changes on scripts/files i just couldnt see the changes on browser
while browsing and googling for like 24 hours i figured out that js scripts should be restarted in order to show the result on browser
and i figured out that in order to start a node js file i should type in terminal
node /dir/example.js
but can someone help me how to refresh/restart it
Iam stuck here like 24 hours
please help
I just want to let you know too that iam using Putty software in order to connect to the ubuntu server, ubuntu version is 20.04

EDIT: you will need an ssh connection to your server with access to a terminal..
Your node.js scripts, if they are on a server, should typically be ran using a process manager such as pm2.
Try to type pm2 list in a terminal. If you see some information you have hit the spot. Just after that run pm2 restart id. id being the number of your process and your changes should be visible.
You can just try this or try your luck with other process managers that run on your server providers. Just read what your server provider recommends for default and usually your previous developer would have used it.

Related

Move my MERN app (developped on windows) on a ubuntu machine and access it via LAN network

It's my first time here so please bear with me :)
Basically i developped a full stack MERN web application on my windows 10 machine (node js, express js and Mongodb in the backend + database and react js for the frontend), to run each one of them for now i use vscode (nodemon server for the backend and npm start for the front) all are running on my localhost on different ports.
what i need to do is to move that MERN app to an ubuntu machine and make it accessible via LAN network of that ubuntu continuously.
i guess i need to use git to move the app from windows to ubuntu? (correct me if i'm wrong) but how to make it run correctly there? and should i install a specific server to run it all on the LAN?
Thank you for the help in advance !

Unable to make my app show with lightsail virtual server

I am trying to upload my site. it's a node.js repo on a linux instance on amazon light sail services.
I uploaded my source code repository to my Virtual Server Instance with static IP using FileZilla through a SSh pem key(all fine i guess..), also I modified the file for the apache server as mentioned in the walk-though tutorial but, I am not able to make it show when I write http://54.87.121.120/spanishwithalex/server/
Before I upload my repo I tried with a simple app that worked perfectly,but now i don't know why it doesn't work. I tried various ports, different locations and various forms but I think I am walking in circles.
I attached some pictures to show where I located my files and the error messages.
I hope it's some how clear.
Thanks
location in my instance
structure repo
error message
apache conf
I'm not great on apache config, but I walked through this enough to get you going:
SFTP or SCP your code to a new folder called /opt/bitnami/apache2/spanishwithalex
Edit /opt/bitnami/apache2/conf/bitnami/bitnami.conf using VIM or whatever and replace every line that has this /opt/bitnami/apache2/htdocs
with this: /opt/bitnami/apache2/spanishwithalex
Restart Apache:
sudo /opt/bitnami/ctlscript.sh restart apache
Let me know if that gets it working for you.

Running Nodejs on Managed Hosting server but the website goes down after some interval

I am facing this problem from last two weeks.
I am accessing and running server from puTTy terminal. Earlier i was facing problem that when i close my puTTy terminal the website showed 503 error, despite of using 'nohup' command.
nohup npm start --production &
Then i tried using 'Screen' , now if i close my terminal , the website is still live but after some hours (20-24) the Screen is dead and the server is also down.
Please give me a solution to run node.js app in production without the hassle of this 503 error

Node.JS: Why is my connection to localhost:3000 refused?

I'm a student going into back-end development for the first time and are trying to learn Node.JS. I downloaded a pdf book about Node.JS from sitepoint called: "Jumpstart Node.JS". In following the instructions to set up the server on the command line, install the dependencies, and navigate to localhost:3000, i got nothing except the following message: "Connection refused: localhost:3000", Can somebody please tell me what might have went wrong and how to fix it?
Edit1:
The instructions i followed is about setting up a node.js server using the Node command line, thus no code, simply cmd commands, however, here is a quick summary of the process i followed:
Created an account on MongoLabs and then a database using the free pricing plan.
Installed express using the command: npm install -g express#.2.5.8.
Created an applications with default options using this command: express authentication.
modified the package.json file in system32
installed the dependencies by typing cd authentication, hitting enter, and then typing the command: npm install
Typed node app and hit enter.
According to the instructions i should have seen a message: "Welcome to express" but instead got the error message.
In following the instructions to set up the server on the command line, install the dependencies, and navigate to localhost:3000
It seems that you didn't start the server.
Somewhere between installing the dependencies and navigating to the URL you need to actually start the server if you want it to serve the request.
Check that there is no copy of the server running in the background, or that another app is using the port currently.
(Your firewall show allow you to see which app has been allocated to that port)
Because nodejs requires it to be the only app on that port running on your computer.
Also try a different port maybe?

Node.js - Server crashes when started on startup, doesn't crash when manually started

I am running Node.js and Socket.io for online chat.
I have created a file in:
/etc/init/example.conf
it has two lines:
start on startup
exec forever start /var/www/example.com/html/server.js //location of server file.
Whenever I start file upload in chat application, it crashes but instantly restarts.
Whenever I kill node process though, and start it manually - it works fine.
I also can't get any logs or anything from terminal as when it's auto started - it doesn't print me anything to terminal.
I am still new to Node.js and Linux in general.
Node.js is running on Express + Jade.
How do I determine specific cause?
I managed to solve my problem, after a bit of searching around I found out about tail command.
My issue was a bit harder to trace because Node.js was a process started by autostart so when I launched terminal and connected to server, process was just running in background basically and I wouldn't get any output (including exception messages).
Anyway, solution that worked for me was:
I typed
ps aux | grep node //to find PID of node process
then I went to following directory
cd /proc/[pid of running node service]/fd
In fd directory there are few objects you can get output from but if you want to attach and listen to servers output including uncaught exceptions, you need 1.
So:
tail -f 1
that way I was able to cause website to crash and see the output.

Categories

Resources