How to install nodejs on Xampp localhost - node.js

Been seeing a lot of how to's on how to install nodejs but nothing is at all clear.
So I ask...
Can someone provide a step by step installation guide for installing and using nodejs on a xampp server?

After searching (source), I have found, that it's easier to install Node.js directly (so, no need of XAMP/WAMP):
Install http://nodejs.org/download/
Create a test file (example) C:\myFolder\test.js and put this code in that file:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');
Open CMD (COMMAND PROMPT) and execute:
node C:\myFolder\test.js
Open this address in your browser: http://127.0.0.1:1337/

Now It's really easy to install and use Node.js even with Apache if you are using Xampp/Wamp etc. Because unlike old days, now Node.js org has created MSI installer for windows.
Below are the steps to install Node.js with Apache. It is assumed that you have already installed xampp
Download windows installer of Node.js from it's site http://nodejs.org/ click on download. Hit the Node.js website and click the big green Install button. It'll detect your OS and give you the appropriate installer. If for some reason it doesn't, click the downloads button and grab the one you need. Run the installer. That's it, you have installed Node.js and, equally, NPM – Node Package Manager – which lets you add all kinds of great stuff to Node quickly and easily.
Note
Keep your Apache and Node ports different. Declare Node port other than 80 or 8080 while creating server in Node because these are the default ports of Apache.
May be these Notes may help someone in future.
1) When Node.js is installed Node and NPM become available globally. Means that you can create your site anywhere on your hard drive and with command prompt go to your directory like in Windows Command prompt
d:/NodeSite/node server.js
and now you can access it via
http://localhost:3000
because your server.js is running with node.
2) Similarly, you can install any Node Package like installing Memcached package or Library
d:/NodeSite/npm install memcached
"NodeSite" is a folder contain your project.
You can see that node and npm have become globals.

It is possible to run NodeJS trough Apache/XAMPP. Great tutorial how to setup httpd.conf / vhosts.conf http://thatextramile.be/blog/2012/01/hosting-a-node-js-site-through-apache
<VirtualHost 109.74.199.47:80>
ServerName thatextramile.be
ServerAlias www.thatextramile.be
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://localhost:3000/
ProxyPassReverse http://localhost:3000/
</Location>
</VirtualHost>
In the end it would be accessible trough port 80 thatextramile.be

I never gave a lot of answers on this site. Because most of the time I'm not an expert however. I had the same issue a while back.
1) You don't really need this XAMPP. Node will create its own http_server so I suggest you just forward calls from XAMPP to the Node app.
2) a good start would be: nodeguide.com/beginner.html
3) I work with PHPstorm which is very nice for Node.js development.
3a) Node.js plugin -> https://www.jetbrains.com/phpstorm/help/installing-updating-and-uninstalling-repository-plugins.html
3b) read this: http://blog.jetbrains.com/webstorm/2014/01/getting-started-with-node-js-in-webstorm/
3c) running: http://blog.jetbrains.com/webstorm/2014/02/running-and-debugging-node-js-application/
3d) Test your app.
You mighht also need this:
4) (MysQl db) https://codeforgeek.com/2015/01/nodejs-mysql-tutorial/

XAMPP and a node.js is two different things, which do not need to work together, nor do they need each other.
XAMPP consists of Apache, MySQL, PHP and Perl.
Where node.js is just like PHP or Apache, so an application.
Node.js can be installed from the website, http://nodejs.org or via the terminal following these instructions:
https://github.com/joyent/node/wiki/Installation

If you want to run javascript from apache you can do it as CGI module. It wont be exacly node.js server and performance because Apache is your server, but you can execute node.js like scripts http://www.cgi-node.org/
You must add a handler to your apache configuration to handle whatever extension files for example .jss via CGI modlue that essentially calls node(.exe) depndeing if linux or windows. I made it work under Bitnami WAMP

It is not possible to install NodeJs on Xammp.
Because Xammp is is simply a tool where Apache,MySql,FileZilla,Tomcat and Mercury server are available. Where you will be able to only configure and use these server.
If you want to install Nodjs on Windows Machine, You will have to install it manually.

Related

Phusion Passenger: 'Initialize language runtime' and 'Load or execute application' error with nodejs app

My nodejs app works fine on my local machine in the dev environment, however getting it to work on the production server is a nightmare.
In a nutshell the app is starting but the content is not loading on the site. It is failing to fully initialize as the screenshot shows.
Screenshot
Anyone have any ideas about this? Even the hosting company isn't sure what is causing it and I can't find anything relevant on google so far. All I know is it is coming from Phusion Passenger...
I will post my solution in case anyone else runs into this issue.
If you have created a nodejs app using express and have used the express generator to set the app up, you will notice the start up file is called www inside the bin folder in your projects directory. Usually it is named app.js.
Phusion Passenger looks for app.js to start the app. You need to tell Phusion Passenger to look for ./bin/www inside your config file. It will likely be different for different systems. In apache it is located here:
/etc/apache2/conf.d/userdata/std/2_4/YOUR_USERNAME/YOUR_DOMAIN/YOUR_APPNAME.conf
You need to add this startup file line:
PassengerStartupFile ./bin/www
Your config file should look something like this:
<Location "/">
<IfModule mod_passenger.c>
PassengerAppEnv "development"
PassengerEnabled on
PassengerBaseURI "/"
PassengerAppRoot "/home/YOUR_USERNAME/YOUR_DOMAIN"
PassengerAppGroupName "YOUR_APP_NAME"
PassengerRuby /opt/cpanel/ea-ruby27/root/usr/libexec/passenger-ruby27
PassengerPython /usr/bin/python
PassengerNodejs /opt/cpanel/ea-nodejs10/bin/node
PassengerAppType node
PassengerStartupFile ./bin/www
</IfModule>
</Location>
Then you just need to save the file, rebuild the apache http config file and restart apache.
I used the terminal inside WHM to run these two lines:
1# /usr/local/cpanel/scripts/rebuildhttpdconf
2# /usr/local/cpanel/scripts/restartsrv_httpd
The instructions in this post are found here:
https://docs.cpanel.net/knowledge-base/web-services/how-to-install-a-node.js-application/

I have Godaddy Shared Web Hosting I need to host node.js website can host site? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Anyone have an idea to host a site or reference for how to install a node server on Godaddy. We have Godaddy shared hosting which provides full Cpanel and looking to customize this shared hosting. What is the step to follow and Is we can able to customize this kind of hosting with editing in the Cpanel setting?
I had tried to host the Node.js website bu not able to get up and running it's shows the pure HTML coded website, not User Interface.
Yes 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 :
1. cgi-node http://www.cgi-node.org/home
Basically 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.
<html>
<body>
<?
var helloWorld = 'Hello World!';
write(helloWorld + '<br/>');
?>
<?= helloWorld ?>
<br/>
<b>I can count to 10: </b>
<?
for (var index= 0; index <= 10; index++) write(index + ' ');
?>
<br/>
<b>Or even this: </b>
<?
for (var index= 0; index <= 10; index++) {
?>
<?= index ?>
<? } ?>
</body>
</html>
OR
2. Standalone Server (this works with NameCheap hosting and GoDaddy shared hosting)
In 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 :
uname -a
Download 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 :
/home/username/bin/node
Open up the .htaccess file in /home/username/public_html and add the following lines :
RewriteEngine on
RewriteRule (.*) http://localhost:3000/$1 [P,L]
Create a file in /home/username/public_html and just call it app.js. Add the following lines in that file :
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('NodeJS server running on Shared Hosting\n');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
SSH into the server run these commands :
cd /home/username/public_html
which node # this should return ~/bin/node
node app.js & # This will create a background process with the server running
If 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.
Yes, this is possible on even the cheapest shared hosting tier. #nebulr instructions are correct. Here is a slightly updated and expanded version for noobs like me.
(1) Enable SSH on your shared hosting account:
• Log into your GoDaddy hosting and turn on SSH Access (on the Dashboard, it's in "Settings" on the bottom right). Take note of the cPanel login username and change the password if you don't remember it. Note that you also may need to create keys in CPanel, under "Security" and "SSH Access".
(2) Install the nodejs program itself:
• Download the Node.js binaries from https://nodejs.org/en/download/ Specifically you'll want the Linux x64 version (direct link https://nodejs.org/dist/v10.15.0/node-v10.15.0-linux-x64.tar.xz)
• Unpack this .tar file on your computer and look inside for the bin folder (on a Mac you may need a program such as The Unarchiver to unpack it). The bin folder will have a file called "node" that's about 40Mb. This "node" file is the only thing we're going to use in this package.
• Using the CPanel File Manager or FTP program, create a folder on the server called "bin" in /home/yourUserName/ and give it permissions of 755. Note this is NOT inside public_html.
• Upload the "node" file to /home/yourusername/bin/
(3) Create a simple nodejs script:
• Open a text editor (like Sublime) and create a new file called "app.js" (or whatever):
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('NodeJS server running on Shared Hosting\n');
});
server.listen(port, hostname, () => {
console.log('Server running at http://${hostname}:${port}/');
});
Note that this is just the basic server app from https://nodejs.org/en/docs/guides/getting-started-guide/
• Open your CPanel File Manager or FTP program, and upload the app.js file to /home/yourusername/public_html/
(4) Modify the .htaccess file:
• Use your FTP program to add these lines to the .htaccess file:
RewriteEngine on
RewriteRule (.*) http://localhost:3000/$1 [P,L]
Note that the .htaccess file is probably blank by default. Also note that you can use nano, vim, or emacs in SSH to edit the .htaccess file if you're brave or 1337.
(5) Start the node server:
• SSH into the godaddy server by opening Putty (Windows) or Terminal (Mac) and at the command line type: ssh username#website.com (where username is your hosting account's cPanel login)
The server should respond with username#website.com's password: which is where you enter the cPanel login password.
Note: If it's your first time SSH'ing to the server, you'll get a message: The authenticity of host 'X.X.X.X' can't be established. RSA key fingerprint is XXXX. Are you sure you want to continue connecting (yes/no)? Type yes and continue on.
• Navigate to /home/yourUserName/public_html/ by typing cd public_html. Start the node server script by typing: node app.js &
In a couple seconds you should see the message: Server running at http://127.0.0.1:3000/
(6) Check it out:
• Open a web browser and type your website's URL. You should get a white page with the text NodeJS server running on Shared Hosting or whatever message you put in line 9 of app.js above. Note that you can't use the IP address on a shared hosting account, you need to use the domain name.
I installed node on godaddy shared hosting with multiple domains by:
SSH to the godaddy server
Install nvm in the home folder
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
nvm install 10.14.0
(or the preferred node version)
Note: if you get nvm command not found when doing $nvm --version, just close and restart the SSH terminal
In the folder of the site you want to run the node app, add the .httaccess file
~/public_html/site folder/.htaccess
RewriteEngine on
RewriteRule (.*) http://localhost:3000/$1 [P,L]
note: .htaccess can be used to target individual folders and changes take effect immediately without having to restart the server.
Run your app.js or node server in the site folder as #nebulr indicated
$node app.js &
One other way to do this is via NVM. First get connected to your server using SSH. Then there's a curl command allowing you to install NVM through a bash script :
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
For me, two additional steps were necessary :
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
Sources:
https://yoember.com/nodejs/the-best-way-to-install-node-js/
https://github.com/creationix/nvmub.com/creationix/nvm
As #nebuir states it is possible to run your node.js developed app using GoDaddy's shared host option because I just did it. The .htaccess portion is extremely key to making this work. The only other line I needed to add was
RewriteRule ^index.html.var$ http://www.yoursite.com:3000/$1 [L,P,QSA]
before
RewriteRule (.*) http://www.yoursite.com:3000/$1 [P,L]
You have two choices to host node app.
- Either buy your own VPS server from godaddy or digitalocean, etc..
- Godaddy itself provide the option to run their node instances. please refer https://in.godaddy.com/pro/one-click-installation/node-js

How can I use (Node) Livereload on a development server in my network

Background: My PHP projects (CakePHP, Wordpress) run on an Ubuntu server in my network, I access them through a development TLD (.dev for example) setup through a local DNS server and I edit the files through a Samba share.
I would like to utilize Livereload for my development, preferably have it running on the server itself. I have basic Node/Gulp knowledge, but haven't been able to get this running.
Livereload (or a middleware server) should proxy the 'real' URLs, making sure all websites run as they would normally and Livereload should be available over the network (so not just localhost, because that runs on the development server)
Desired result:
Livereload runs on my dev server (IP: 10.0.0.1), my project is called helloworld.dev, I browse to 10.0.0.1:3000 on my machine and see helloworld.dev proxied through Livereload. I now edit a CSS file over the Samba share and the CSS is reloaded without a refresh.
I've tried using a few NPM packages, gulp-livereload, livereload, node-livereload, with their provided examples that come with the packages, but haven't been able to get the desired result. They all expect you to run in locally, don't support access to the Livereload URL over the network, cannot proxy the 'real' URLs or require static content.
Can anyone provide an example or 'proof of concept' code of my wish, so I can see where to start?
I found the answer: http://nitoyon.github.io/livereloadx/
This does EXACTLY what I need.
I can run
livereloadx -y http://helloworld.dev -l
open
http://serverip:35729
and I'm ready to roll.
The -y option creates the proxy to the 'real' URL and the -l makes it serve files from local filesystem instead of through its proxy.

Beginner - setting up local host for Angular app using XAMPP on Windows 7

I have taken a Angular App which works on Local host when I use visual studio IIE server.
I don't want to use Visual Studio and I am trying to test the app locally using XAMPP.
I am a complete beginner, and I cannot get the local host to pick-up the html initialization file. I have checked the following:
Skype is off and the port is set to 80 in XAMMP
the root server in HTTPd.conf is setup correctly (no slash at end)
I am getting a little confused as to 'how' angular will work on the XAMMP local host.
Do I need to get Yeoman or grunt (seen these apps in some posts, but they seem to be for command line environment).
Any help, or even a pointer to a step by step set-up would be great!
Angular is no different from a normal html web page, when it comes to working in a localhost.
Does your XAMPP work with standard HTML files?
Do you have any error generated?
OK. Got this sorted. I was over complicating things entirely, angular runs sweet on regular XAMPP, no Grunt/ Yeoman etc. required.
All you need to do is: 1. install XAMPP 2. Close Skype 3. Place you app, libraries and everything else in the folder C:\xampp\htdocs\
localhost/Angularappstartpage.html
BOOM!
it works.
You may need to adjust the port number on the localhost (default is 80 e.g. localhost:80/...)
You can also change the root folder in your XAMPP config setup to point to your local GIT.
Do this by changing the line in the HTTPD.conf file (click 'config' on the apache module)
DocumentRoot "C:/xampp/htdocs" to DocumentRoot "C:/myLocalGIT"
Hopefully this will help all the new guys out there. Good luck!
Skype blocks the port 80, which is used for browsing. XAMPP uses the same port so exactly.
https://support.skype.com/en/faq/FA148/which-ports-need-to-be-open-to-use-skype-for-windows-desktop
If you use mysql, also open first XAMPP and start your services and then keep working on your SO as always.

PHP JAVA Bridge

I am very new to Linux but I am trying best to learn. We have dedicated hosting server of CentOS 6. It is configure with Apache Server as our public website. Now we need to install PHP JAVA Bridge on it.
What I did is, I install TomCat 6 and jdk 1.6. Then I copy JavaBridge.war file to $CATALINA_HOME/webapps folder and jar files on $CATALINA_HOME/lib folder. When I check from tomcat 8080 port JavaBridge is working very good.
Then I make symlink of $CATALINA_HOME/webapps/JavaBridge on my apache server. Untill here everything is okay
But when I try to browse from browser like http://www.xxx.com/JavaBridge I will get following error
You don't have permission to access /JavaBridge/ on this server.
Apache Server at www.gizeleonline.com Port 80
Now my question is that do I am doing it in wrong way or do I have to get rid of Apache server or I am missing something.
Kindly help on this experts :)
Actually it was my mistake. I just re-image my server and re-install everything it start working everything. thanx for help every body

Resources