2

I know there is Node.js and Rhino, amongst other platforms to run server side JS. Though, we can only afford a shared server, since a VPS is much more expensive, and normally shared servers do not provide such tools. We need to run some cron jobs which by default are run by the server, and our core functions are purely JS without interaction with the browser/client.

Is there then a simple way of running server side JS, without the need for installing server side specific SW?

Aónio
  • 579
  • 4
  • 13
  • You can't run NodeJS on a shared hosting. – Andrius Nov 19 '15 at 13:47
  • 1
    @Andrius and what makes you say that? Ultimately, node is just an executable so you should be able to deploy it alongside your code and trigger it by your cron job. – James Nov 19 '15 at 14:03
  • @James , you're saying that a shared hosting will let you run shell commands? I doubt that. There are specific commands that are allowed but I doubt that Node is allowed (at least by most providers). – Andrius Nov 19 '15 at 14:05
  • 1
    @Andrius I'm talking theoretically, we have no idea what provider the OP is intending on using so I can't comment on whether it is _definitely_ possible. Also, the question is about the ability to run JS on the backend without having to install anything, you can 100% do that with Node. – James Nov 19 '15 at 14:08
  • @James, I'm sending a link to my server provider (Hostgator) and they do not allow Node.js on a shared server: http://support.hostgator.com/articles/pre-sales-policies/compatible-technologies – Aónio Nov 19 '15 at 14:55
  • @Aónio that means it doesn't come pre-installed, but like I said, Node comes as a pre-compiled executable therefore you should be able to deploy it to your shared environment and, assuming you have the ability to execute applications, then you should be able to run it. According to the [docs](http://support.hostgator.com/articles/cpanel/what-do-i-put-for-the-cron-job-command), it certainly looks possible to do this on Hostgator. – James Nov 19 '15 at 15:20
  • @James do you refer to [this](https://nodejs.org/dist/v4.2.2/node-v4.2.2-linux-x86.tar.gz) node.js executable? The link you sent says that cron may run PHP script, but doesn't say anything about running JS scripts. Thanks for the info. – Aónio Nov 19 '15 at 17:49
  • It seems this question [was already partially answered](http://stackoverflow.com/questions/24777750/how-to-host-a-node-js-application-in-shared-hosting). – João Pimentel Ferreira Nov 19 '15 at 19:54

1 Answers1

3

1) Go to Node.js download page and get the link for the Linux Binaries (.tar.gz) (right click-> copy link address).

2) Then (thanks to user niutech) create the following php file, namely install_node.php

<?php
//Download and extract the latest node
exec('curl http://the_URL_you_copied | tar xz');
//Rename the folder for simplicity, adapt accordingly
exec('mv node-v#bla_bla-linux node');
?>

3) run the php file from the unix terminal

$php -q install_node.php

4) you may then run the node executable file on ./node/bin/node

Community
  • 1
  • 1
João Pimentel Ferreira
  • 14,289
  • 10
  • 80
  • 109