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.
-
I've written a Node.JS deploy guide, with examples, which might be of some use to you: gun.io/blog/tutorial-deploy-node-js-server-with-exampleRich Jones– Rich Jones2012-01-14 20:38:37 +00:00Commented Jan 14, 2012 at 20:38
-
1This question is more about how to write a node application than how to deploy one. It's a little misleading.Darren– Darren2013-08-01 10:09:38 +00:00Commented Aug 1, 2013 at 10:09
-
possible duplicate of How to deploy a Node.js application?Hardik Sondagar– Hardik Sondagar2013-10-16 07:21:40 +00:00Commented Oct 16, 2013 at 7:21
-
For whatever reason, the link in the first comment does NOT go to a page about deploying a node server. I don't have the time to look around for it. I'll look elsewhere.John Deighan– John Deighan2022-12-08 03:31:18 +00:00Commented Dec 8, 2022 at 3:31
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.
Comments
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.
Comments
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.