Jump to content

[Solved] Node.js Hello World


cmh

Recommended Posts

I want to install a discordbot, but I can't even run a simple application. Where is my mistake? Server; tommy, user cmh

I deployed few days ago. 

unknown.png

 

 

app.js
 

unknown.png

 

register app
 

 

unknown.png

 

where is my mistake?
on the url i have 404
 
 

unknown.png

Edited by cmh
Link to comment
Share on other sites

Posted on discord:

Krydos — Today at 12:42 AM

Try renaming /home/cmh/public_html/.htaccess for a minute and see if it works

Your domain is automatically redirecting to add www to the front and that's probably causing the 404 error

The other issue I'm seeing is your application manager shows the application is supposed to be located at /home/cmh/pingpbot/ but that directory doesn't exist. There is a pingbot directory (without the p in the middle) so probably just a typo.

Link to comment
Share on other sites

Make sure you have all the dependencies installed inside the node_modules folder.

i copy this folder from my pc. should be ok, but...

also i found log

npm WARN union-slave@1.0.0 No repository field.

audited 94 packages in 1.419s

4 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

1618419982.98945
Task completed with exit code 0

Edited by cmh
Link to comment
Share on other sites

Literally all I did was log in to your account and click the button to enable your node app in the application manager, and now it works.

 

http://bot.cmh.heliohost.org/

 

Something you may not be aware of is this

In order for the Node.js application to be deployed it requires an Apache restart so this could take anywhere from a few minutes to a few hours. If it's been more than 2 hours and it still isn't working, please open a customer service ticket and let us know.

Source: https://wiki.helionet.org/tutorials/node.js
  • Like 1
Link to comment
Share on other sites

Unfortunately, no. Yes, the server at the domain displays the message, but the bot does not work, even  status is Online.

And I think that it started because of the cron. And now I can not restart it, kill the process

 

P_text - hosted on heliohost.

HelioBot - on my pc

 

Sorce Code is same
Edited by cmh
Link to comment
Share on other sites

I think you're confusing and combining guides.

 

The discord bot guide is more applicable to what you're trying to do I think. https://wiki.helionet.org/tutorials/discord-bot This guide is for starting and stopping a bot that runs more or less constantly. You'll still want to use python cgi to start and stop your bot, but instead of a python script for the bot you'll be running a node script.

 

This is a passenger node.js guide. https://wiki.helionet.org/tutorials/node.js This guide is for setting up a node.js website through passenger. The way passenger works is when someone requests your page passenger starts up the node app and the visitors gets to interact with the website. Then after the website visitor goes away passenger stops the node app to save system resources. This obviously won't work well for a bot because you don't want your bot to only be online for 5 minutes everytime someone visits your website.

Link to comment
Share on other sites

you use a python script to start and stop the bot

start.py in public_html/cgi-bin:

#!/usr/bin/python3.7

import os, subprocess, signal

print("Content-Type: text/html\n\n")

counter = 0
p = subprocess.Popen(['ps''-u''mule'], stdout=subprocess.PIPE)
# must match your username --------^^^^^^^^

out, err = p.communicate()
for line in out.splitlines():
  if 'node'.encode('utf-8'in line:
#     ^^^^^^^^^^^----- this has to match the filename of your bot script

    counter += 1
    print("Bot already running.")

if counter == 0:
  subprocess.Popen("/usr/bin/node /home/mule/node/index.js"shell=True)
#                         ^^^^^^^^-- be sure to update it to your username

  print("Bot started!")

and stop.py in same location:

#!/usr/bin/python3.7

import ossubprocesssignal

print("Content-Type: text/html\n\n")

counter = 0
p = subprocess.Popen(['ps''-u''mule'], stdout=subprocess.PIPE)
# must match your username --------^^^^^^^^

outerr = p.communicate()
for line in out.splitlines():
  if 'node'.encode('utf-8'in line:
#     ^^^^^^^--- this has to match the filename of your loop

    counter += 1
    pid = int(line.split(None1)[0])
    print("Stopping bot.")
    os.kill(pidsignal.SIGTERM)

if counter == 0:
  print("Already stopped.")
Link to comment
Share on other sites

I have no idea why it works for you, but it doesn't work for me. I took your code, but I see error 500.

 

Of course, all files and folders have 755 permissions, including cgi-bin.

start.py:



#

Edited by cmh
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...