Home » Categories » Multiple Categories |
How To Install And Run A Node.js App On Centos 6.4 64bit |
Article Number: 222 | Rating: Unrated | Last Updated: Sun, Jan 5, 2014 at 8:49 PM
|
Node.js installationNow that we're ready to install Node.js from sources. First, we'll move to /usr/src directory - the usual place to hold software sources.cd /usr/srcNow, we pick the latest compressed source archive from Node.js website at http://nodejs.org/download/. wget http://nodejs.org/dist/v0.10.4/node-v0.10.4.tar.gzWe could and should replace the url and use the more recent version of node.js, if there is one. Next, we are uncompressing the source files and move into that directory. tar zxf node-v0.10.4.tar.gz cd node-v0.10.4Now the source for Node.js is extracted and we're in the source directory. We can now prepare our compiler commands, by executing the configure script: ./configureIt will read the properties of our system to prepare compiler flags. Ie. it could be a system architecture (32/64bit, CPU specific flags etc). With it, we're ready to actually compile the source now. To do that, just type: makeThis is probably the most time-consuming task here: on my example server it took about 6 minutes and 34 seconds to complete. When we're done, we need to make this available system-wide: make installThe latest command will place the compiled binaries in system path, so all users could use it without any further setup. By default, node binary should be installed in /usr/local/bin/node. Install Express.jsWe now have Node.js installed and complete, we can start developing right away, deploy an already done application or we can proceed to create our Express.js application. First, we'll use npm, nodes' module manager, to install express middleware and supervisor - a helpful module that keeps our app started, monitors for file changes (ie. when we're developing the app) and restarts the server when needed.UPDATE: To be able to run an executable in /usr/local/bin through sudo, you have add /usr/local/bin to your secure_path using visudo. sudo visudoLook for secure_path, and append the following to it: ":/usr/local/bin". Once you have done that, you're now ready to install the express and supervisor modules. npm -g install express supervisornpm -g install will install the express and supervisor modules from npm software repository and make it available to the whole system. The -g switch in this command means "global" - the express and supervisor commands will be available accross the whole system. Add non-privileged userYou should now, for security reasons, create a regular system user and run node under non-privileged account. To do this, add the user first. You can replace "exampleuser" with whatever name your prefer.useradd exampleuserWe have a new system user. Add a decent password for the new user: passwd exampleuserLog out, and log back in as the new user. This changes our login shell from root (system user) to exampleuser (non-privileged user who can compromise the system with less damage). Creating an express appExpress is powerfull framework, and to create our first application, all we have to do is type:express helloThe command will create a "hello" directory and setup some basics for a new application. Now we should enter this directory and install express dependencies: cd hello && npm installnpm install part of the command will read all the module dependencies from a generated package.json file and install it from npm software repository. We should start a new screen session so we can leave node app running: screenFinally, we can start our application with the help of supervisor that we installed earlier. supervisor appNow we're able to access our first express app at your server IP. For example http://123.456.78.90:3000/. |
Attachments
There are no attachments for this article.
|
How To Create Nagios Plugins With Ruby On CentOS 6
Viewed 2909 times since Sat, Jan 4, 2014
How To Set Up an NFS Mount on Ubuntu 12.04
Viewed 10300 times since Tue, Dec 24, 2013
How To Install Wordpress with nginx on CentOS 6
Viewed 9208 times since Sat, Jan 4, 2014
How To Use Yaourt to Easily Download Arch Linux Community Packages
Viewed 4113 times since Fri, Dec 27, 2013
How To Deploy Node.js Applications Using Systemd and Nginx
Viewed 9568 times since Sat, Jan 4, 2014
How To Create Nagios Plugins With Perl On CentOS 6
Viewed 2559 times since Sat, Jan 4, 2014
How To Copy Files With Rsync Over SSH
Viewed 6520 times since Fri, Dec 27, 2013
How To Install an Upstream Version of Node.js on Ubuntu 12.04
Viewed 2625 times since Sun, Dec 29, 2013
How to Get Started With mod_pagespeed with Apache on an Ubuntu and Debian Cloud Server
Viewed 3807 times since Thu, Dec 26, 2013
How to Setup and Configure an OpenVPN Server on CentOS 6
Viewed 3048 times since Tue, Dec 31, 2013
|