简体   繁体   中英

Host node.js project online

I've got a small node.js and socket.io project that i would like to run online on my server. I used jade for my files, and packaged it complete using npm install. So everything is in my local folder. I can also run it locally which works.

But i want to connect my phone to control my browser and i can't connect my phone to a localhost. So I need to run it online.

The problem is when I put it online i've got a index.jade file. This one doesn't get recognized by the browser as webpage. So i only get a forbidden page when i go to http://www.woutervdkamp.nl/iphoneconnect/views

my folder structure is like:

└── httpdocs
   ├── iphoneconnect
   |  ├── node-modules
   |  ├── express
   |  ├── jade
   |  └── socket.io
   ├── package.json
   ├── server.js
   └── views
      ├── index.jade
      └── mobile.jade

Do I need to use a special host for it? Or can someone point me in the right direction! Thanks in advance.

I'm trying to make something like this: http://sportyfinger.lecoqsportif.com/uk-en/connexion

If anyone got a good tutorial for that would be nice! I only would like to know how to set up the connection between iphone and webbrowser! Already got something right now but it's bit slow.

Greets,

Wouter

First of all, you might got lost in understanding what is happening.

Your current method is to serve node.js project as static site, using Apache.

That is not going to work, your node.js project consists of instructions , and to parse these instructions you need a program. That program is called node.js , not Apache or anything else.


Most webhosting companies you will find do not support node.js at all. The solution is to find a specific node.js hosting service or virtual/cloud hosting instead.

Some of appropriate for the task hosting companies 1 are: Heroku, OpenShift, Digital Ocean.

After choosing, you will have to setup simple Linux server using the supplied colorful guidance and then install node.js program before running your project.

After you have Linux ready, you have to install node.js there and run your project the same way as if it was on localhost.

Summarizing all I said:

  1. Find the hosting company with node.js or shell access.
  2. Setup linux OS (I suggest Ubuntu ) through the hosting company tools. (easier than it sounds, don't worry)
  3. Run the following commands to get node.js on your fresh linux server:

    sudo add-apt-repository ppa:chris-lea/node.js

    sudo apt-get update

    sudo apt-get install python-software-properties python g++ make nodejs

  4. Copy the project files to the server

  5. Navigate to the project location on the server and run it as you would do on localhost: node.js server.js

1 - Comparison of Hosting companies by @Vinz243

I am also doing some simple node.js web app recently and I think Heroku is a very friendly hosting websites for new developers.

For hosting on heroku, you do not need to run sophisticated bash commands. The method that heroku recommends is that you install a tool called heroku to the terminal but it is not necessary. Just add a remote to the heroku repository(which you can create on their website) and push your source code to that remote repository and you can see from the command line that heroku will automatically detect, compile and host the node.js web application for you.

git push heroku master

btw, Heroku also has database and logging add-ons.

For your reference:

https://devcenter.heroku.com/articles/getting-started-with-nodejs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM