Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I deploy a Node.js application?

Tags:

node.js

Node.js is "JavaScript on the server". OK. But, how can I "deploy" a Node.js application? Which kind of web server should I use? How can I create "Controllers"? And how can I persist data in a DB? Thanks in advance.

like image 763
sonnuforevis Avatar asked Sep 19 '11 17:09

sonnuforevis


3 Answers

This is one of the best places to get familiar with what's currently available: https://github.com/joyent/node/wiki/modules.

Regarding "which kind of web server" you should use, it depends on what you're trying to build. I currently use express, which I've been very happy with.

For database connectivity, that depends on what type of database you're connecting to. For MongoDB, I use Mongoose, and for CouchDB I just use a raw HTTP client. If you need MySQL, the most popular one right now seems to be node-mysql. There are lots of other database drivers here.

Given the high-level nature of your question, it sounds like you might be better profited by some "getting started" guides, to really get familiar with what node.js is. There are several good articles here, for example. From there you can move into web servers and database drivers more comfortably.

like image 125
jmar777 Avatar answered Sep 22 '22 19:09

jmar777


There are many deployment solutions available, CloudFoundry being one of them. I think you need a great understanding of how Node works first though. Basically, to "deploy" an application, you would typically send the files over to the server and run it from the commandline:

node server.js

There is no web server involved like Apache or nginx. If your application needs a web server, there are some solutions in Node like Express.

Databases work as usual. You install one over to your server, use one of the many Node modules to connect to it and write data. It's separate from your Node server.

Check out this excellent list of Node modules from the GitHub wiki.

like image 37
Alex Turpin Avatar answered Sep 23 '22 19:09

Alex Turpin


You should start by looking at http://nodejs.org. Great place to find information when writing code. There are a lot of modules that you can use or you can start from scratch and work your way up.

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/');

Easiest example of an web server written in node.

like image 26
Marcus Granström Avatar answered Sep 23 '22 19:09

Marcus Granström