You are on page 1of 3

13/10/2017 How to host a Node.

Js application in shared hosting - Stack Overow

Learn,Share,Build
Eachmonth,over50milliondeveloperscometoStackOverflowto Google Facebook
learn,sharetheirknowledge,andbuildtheircareers. OR

Jointheworldslargestdevelopercommunity.

HowtohostaNode.Jsapplicationinsharedhosting[closed]

HowtohostaNode.Jsapplicationinsharedhosting

Iwanttohostanode.jsapplicationinsharedhosting.Doesanyonehaveanyreferenceordocumentationtoreferto.

thanksinadvance

node.js webhosting

askedJul16'14at9:55
somesh
1,409 1 10 9

closedasofftopicbyDanCornilescu,showdev,AnikIslamAbhi,ivan_pozdeev,ValentynShybanovDec2'15at3:33
Thisquestionappearstobeofftopic.Theuserswhovotedtoclosegavethisspecificreason:

"Questionsaskingustorecommendorfindabook,tool,softwarelibrary,tutorialorotheroffsiteresourceareofftopicforStackOverflowastheytendto
attractopinionatedanswersandspam.Instead,describetheproblemandwhathasbeendonesofartosolveit."DanCornilescu,showdev,AnikIslamAbhi,
ivan_pozdeev,ValentynShybanov

Ifthisquestioncanberewordedtofittherulesinthehelpcenter,pleaseeditthequestion.

Thewayifigureditbyrunningnpmbuildwillgeneratejsfileswhichyoucanminifyandthenincludethenin
yourscripttags.Examplewhenbuildingwithvuejsorevenangular2cliGEOFFREYMWANGIMay21at
12:49

5Answers

Youcanrunnode.jsserveronatypicalsharedhostingwithLinux,ApacheandPHP(LAMP).I
havesuccessfullyinstalledit,evenwithNPM,ExpressandGruntworkingfine.Followthe
steps:

1)CreateanewPHPfileontheserverwiththefollowingcodeandrunit:

<?php
//Download and extract the latest node
exec('curl http://nodejs.org/dist/latest/node-v0.10.33-linux-x86.tar.gz | tar xz');
//Rename the folder for simplicity
exec('mv node-v0.10.33-linux-x86 node');

2)Thesamewayinstallyournodeapp,e.g.jtjssample,usingnpm:

<?php
exec('node/bin/npm install jt-js-sample');

3)RunthenodeappfromPHP:

<?php
//Choose JS file to run
$file = 'node_modules/jt-js-sample/index.js';
//Spawn node server in the background and return its pid
$pid = exec('PORT=49999 node/bin/node ' . $file . ' >/dev/null 2>&1 & echo $!');
//Wait for node to start up
usleep(500000);
//Connect to node server using cURL

https://stackoverow.com/questions/24777750/how-to-host-a-node-js-application-in-shared-hosting 1/3
13/10/2017 How to host a Node.Js application in shared hosting - Stack Overow
$curl = curl_init('http://127.0.0.1:49999/');
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
//Get the full response
$resp = curl_exec($curl);
if($resp === false) {
//If couldn't connect, try increasing usleep
echo 'Error: ' . curl_error($curl);
} else {
//Split response headers and body
list($head, $body) = explode("\r\n\r\n", $resp, 2);
$headarr = explode("\n", $head);
//Print headers
foreach($headarr as $headval) {
header($headval);
}
//Print body
echo $body;
}
//Close connection
curl_close($curl);
//Close node server
exec('kill ' . $pid);

Voila!HavealookatthedemoofanodeapponPHPsharedhosting.

EDIT:IstartedaNode.phpprojectonGitHub.

editedDec31'14at4:21 answeredDec10'14at1:04
niutech
14.9k 10 50 70

1 andinstallingmongoDBtoo?jskyJan6'15at2:43

3 @jskyItshouldbepossiblesincemongodbdoesn'tneedroot.Justfollowthemanualinstallguide.niutech
Jan6'15at11:41

1 Haven'ttriedit,butlooksjustbeautiful!!!...NicejobGabrielRodriguezSep25'15at14:10

2 BeadvisedyoushallupdatethedownloadURLaccordinglyJooPimentelFerreiraNov19'15at19:47

3 node.phpisverygood!HemantSharmaNov21'15at6:02

ConnectwithSSHandfollowtheseinstructionstoinstallNodeonasharedhosting

InshortyoufirstinstallNVM,thenyouinstalltheNodeversionofyourchoicewithNVM.

wget -qO- https://cdn.rawgit.com/creationix/nvm/master/install.sh | bash

Yourrestartyourshell(closeandreopenyoursessions).Thenyou

nvm install stable

toinstallthelateststableversionforexample.Youcaninstallanyversionofyourchoice.
Check node --version forthenodeversionyouarecurrentlyusingand nvm list tosee
whatyou'veinstalled.

Inbonusyoucanswitchversionveryeasily( nvm use <version> )

There'snoneedofPHPorwhichevertrickyworkaroundifyouhaveSSH.

answeredNov22'15at16:49
vinyll
6,972 2 17 21

Hi,thanksfortheanswer.Although,Iamrunningintotrouble,itsaysthatnodeisnotfound,onceIdothe
installusingnvm.Anyhelp?AmitSaxenaJan4at13:12

Maybeshouldyoutrystackoverflow.com/a/33874050/328117ifyouhavethatnodenotfounderrorwithnvm
vinyllJan20at23:35

Mostsharedhostingprovidersdon'tgiveSSHaccess.Atleastnotmine.arvindpdmnFeb21at5:06

ThisworkedonasharedhostonhostgatorIkbelMar11at22:06

Workedperfectly!!ThanksDevinNorgarbMar19at13:28

IinstalledNode.jsonbluehost.com(asharedserver)using:

wget <path to download file>


tar -xf <gzip file>

https://stackoverow.com/questions/24777750/how-to-host-a-node-js-application-in-shared-hosting 2/3
13/10/2017 How to host a Node.Js application in shared hosting - Stack Overow
mv <gzip_file_dir> node

Thiswilldownloadthetarfile,extracttoadirectoryandthenrenamethatdirectorytothename
'node'tomakeiteasiertouse.

then

./node/bin/npm install jt-js-sample

Returns:
npm WARN engine jt-js-sample@0.2.4: wanted: {"node":"0.10.x"} (current:
{"node":"0.12.4","npm":"2.10.1"})
jt-js-sample@0.2.4 node_modules/jt-js-sample
express@4.12.4 (merge-descriptors@1.0.0, utils-merge@1.0.0, cookie-
signature@1.0.6, methods@1.1.1, cookie@0.1.2, fresh@0.2.4, escape-html@1.0.1,
range-parser@1.0.2, finalhandler@0.3.6, content-type@1.0.1, vary@1.0.0,
parseurl@1.3.0, serve-static@1.9.3, content-disposition@0.5.0, path-to-
regexp@0.1.3, depd@1.0.1, qs@2.4.2, on-finished@2.2.1, debug@2.2.0, etag@1.6.0,
proxy-addr@1.0.8, send@0.12.3, type-is@1.6.2, accepts@1.2.7)

Icannowusethecommands:

# ~/node/bin/node -v
v0.12.4

# ~/node/bin/npm -v
2.10.1

Forsecurityreasons,Ihaverenamedmynodedirectorytosomethingelse.

editedMar20'16at7:48 answeredMay31'15at18:11
SHAZ iiboone.com
2,276 6 16 28 86 1 5

1 Itried npm start inthe jt-js-sample andIwenttomysite.com:5000butitsaidpagenotavailable.Do


IneedtogototheIPaddressinstead?zachdyerJun5'15at17:54

A2Hostingpermitsnode.jsontheirsharedhostingaccounts.IcanvouchthatI'vehada
positiveexperiencewiththem.

HereareinstructionsintheirKnowledgeBaseforinstallingnode.jsusingApache/LiteSpeedas
areverseproxy:https://www.a2hosting.com/kb/installableapplications/manual
installations/installingnodejsonmanagedhostingaccounts.Ittakesabout30minutestoset
uptheconfiguration,andit'llworkwithnpm,Express,MySQL,etc.

Seea2hosting.com.

answeredSep12'15at5:49
aap
309 2 8

1 Thankyou!JustwhatIwaslookingfor.PedroFerreiraApr27at0:20

Youshouldlookforahostingcompanythatprovidessuchfeature,butstandardsimple
static+PHP+MySQLhostingwon'tletyouusenode.js.

Youneedeitherfindahostingdesignedfornode.jsorbuyaVirtualPrivateServerandinstallit
yourself.

answeredJul16'14at10:00
Marek
481 2 7 20

doyoumeanitisnotpossibletohostNode.jsapplicationusingsharedhosting somesh Jul16'14at


10:04

2 @someshItispossibleseemyanswer.niutechDec10'14at1:04

It'sacooltrick,thoughkeepinmindalotofsharedhostingproviderswillkillthisprocessandconsiderit
misuseofasharedhostingaccount...TiagoFeb6at17:16

technicallypossibleas@niutechsaid,butIdefinitelywouldn'tconsideritproductionsafe,othercolleague
(cannotmentionmorethanoneuser)isright,Ibelievemosthostingproviderswillkillthenodeprocessor
youwouldrunoutofprocessorcycletimeverysoonMarekFeb6at23:15

https://stackoverow.com/questions/24777750/how-to-host-a-node-js-application-in-shared-hosting 3/3

You might also like