Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Chris Skinner
Chris Skinner
3,807 Points

Setting up a server to run my node.js app

Hi,

I've done the Node.js course and just created a node app and want to deploy it to a server. However I'm not sure how to set up the server to run my app.js file.

Here's my app in short: When testing in the console I type node app.js and the app runs - I have a local server started at localhost:3000

I then enter some parameters i.e. ?Param1=23432&Param2=112344 to the URL. The app then grabs these params and updates an API - once finish it redirects to a different URL.

It's similar to the Node.js course about the student profile.

So my question is. I now want to make this live. I have a bitnami server I want to put it on. What and how do i go about doing this.

Thanks

4 Answers

I have never used Bitnami so I can't say personally, but it looks like they help you set up a Node stack on their Cloud here: https://bitnami.com/stack/nodejs

Chris Skinner
Chris Skinner
3,807 Points

Thanks - that's helped. However I am more concerned with the setup once the server is ready - the next step to getting it up and running. Do I just upload my app.js file to the server and enter the IP in my address bar? What simulates the $node app.js command I type into the console to get everything up and running / ready?

I recommending taking a look through their documentation. This might be a good place to start: https://wiki.bitnami.com/Infrastructure_Stacks/Bitnami_Node.js_Stack

One of the most important dev skills I can think of is learning how to navigate documentation for different technologies. A lot of learning can take place when you do this and I think this is a pretty good opportunity :D

Chris Skinner
Chris Skinner
3,807 Points

Thanks again - yes I've read through all of that but still stumped. I agree about it being a good learning opportunity but some guidance when learning something new is also helpful and saves a lot of time. There isn't really an explanation for what I'm looking for on those docs.

My questions which the docs don't answer are as follows:

1) Is there a particular dir to upload my app into 2) Once there how do I simulate the node app.js command that I have been running whilst developing locally (node app.js). 3) I uploaded the files to a server I created, located my app folder and ran node app.js from within the console - but as soon as I close the console on my mac the app will stop... how do I get the app to continuously run (it listens for input into the url using queryString so I need the app up and running listening on an ip address). 4) Do I have to install express to get my app to work?

Currently in my app I have the following:

const router = require('./router.js');

// Setup Server
const http = require('http');

http.createServer(function (request, response) {
  router.home(request, response);
  router.user(request, response);
}).listen(3000);
console.log('Server running at http://<workspace-url>/');

Do I need the createServer in this case - when I deploy or is this only for development / testing. Now that I'm putting it up on a server.