1Yes this is possible. Somehow I have never seen anyone actually answer this question correctly. This works with the most basic shared hosting plans. I have successfully been able to set it up a couple different ways. I think the second is probably what you want :
2
31. cgi-node http://www.cgi-node.org/home
4
5Basically this replaces PHP on the lamp stack. You can run javascript through node like you would run PHP. This has all the same functionality of node js but is only really geared towards template rendering.
6
7 <html>
8 <body>
9 <?
10 var helloWorld = 'Hello World!';
11 write(helloWorld + '<br/>');
12 ?>
13 <?= helloWorld ?>
14 <br/>
15 <b>I can count to 10: </b>
16
17 <?
18 for (var index= 0; index <= 10; index++) write(index + ' ');
19 ?>
20 <br/>
21 <b>Or even this: </b>
22 <?
23 for (var index= 0; index <= 10; index++) {
24 ?>
25 <?= index ?>
26 <? } ?>
27
28 </body>
29</html>
30OR
31
322. Standalone Server (this works with NameCheap hosting and GoDaddy shared hosting)
33
34In your shared hosting account you will need SSH in order to do this. So you may need to upgrade or request SSH access from their customer support. Download the latest NodeJS https://nodejs.org/en/download/. The shared hosting is probably in linux 64 bit. You can check this on linux or unix by running :
35
36uname -a
37Download the Linux binaries and put the bin/node (and the bin/npm file if you want to use npm on the server) file from the download in /home/username/bin/ (create the bin folder if it doesn't exist) on the server. Put permissions 755 on the node binary. So you should have a new file here :
38
39/home/username/bin/node
40
41Open up the .htaccess file in /home/username/public_html and add the following lines :
42
43RewriteEngine on
44RewriteRule (.*) http://localhost:3000/$1 [P,L]
45Create a file in /home/username/public_html and just call it app.js. Add the following lines in that file :
46
47const http = require('http');
48
49const hostname = '127.0.0.1';
50const port = 3000;
51
52const server = http.createServer((req, res) => {
53 res.statusCode = 200;
54 res.setHeader('Content-Type', 'text/plain');
55 res.end('NodeJS server running on Shared Hosting\n');
56});
57
58server.listen(port, hostname, () => {
59 console.log(`Server running at http://${hostname}:${port}/`);
60});
61SSH into the server run these commands :
62
63cd /home/username/public_html
64which node # this should return ~/bin/node
65node app.js & # This will create a background process with the server running
66If you can get this set up right this will save you a ton of money in the long run as opposed to using something like AWS or Heroku etc.