Services     Software     Commentary     Design     Astral Musings   
tips and best practices

rickatech 2015-05



Reference [edit]

Updating this page for CentOS 7, systemd, and more modern yum repositories.

RHEL/CentOS 7 Install
rickatech 2015-07

Elsewhere [edit]

Core Node.js functionality has not yet been mainlined into the base RHEL repositories, however the venerable and stable EPEL repository provides a viable workaround.  The node community has its own captive package management system called npm not surprisingly.  Though npm is not mandatory to be able to run service side javascript, odds are there will be something one needs that is best obtained/updated through that service.

# cat /etc/redhat-release 

  CentOS Linux release 7.1.1503 (Core) 

# yum install epel-release

# yum install nodejs

# rpm -qa

  > libuv-0.10.34-1.el7.x86_64
  > v8-
  > nodejs-0.10.36-3.el7.x86_64
  > gpg-pubkey-352c64e5-52ae6884
  > http-parser-2.0-4.20121128gitcd01361.el7.x86_64
  > epel-release-7-5.noarch
  > c-ares-1.10.0-3.el7.x86_64

# node --version


# yum install npm

# rpm -qa

  > nodejs-semver-2.1.0-3.el7.noarch
  > nodejs-rimraf-2.2.2-1.el7.noarch
  > ...
  > gcc-c++-4.8.3-9.el7.x86_64
  > npm-1.3.6-5.el7.noarch 

$ cat example.js 

  var http = require('http');

  http.createServer(function (req, res) {
	res.writeHead(200, {
		'Content-Type': 'text/plain'
	res.end('Hello World\n');
	}).listen(1337, "");

  console.log('Server running at');

$ node example.js

  [ switch to another local terminal ]

$ wget http://localhost:1337/any

$ cat any 

  Hello World 

rickatech 2015-08


Although Node.js provides a basic framework for running server side javascript in a manner that can accept web/http requests, it does not provide a standard daemon to allow this to occur in the background like venerable web services like Apache/httpd.  Fortunately this is something Linux/Unix is extraordinarily gifted at supporting, and with more recent systemd services, it is rather straightforward to place some directives in a daemon file to allow as many javascripts applets to run asynchronous as you like.

# pwd


# ls -lh no*


$ systemctl status nodesvr-ricktest

  nodesvr-ricktest.service - Node.js Example Server
  Loaded: loaded (/home/rickatech/node/sysd)

$ cat nodesvr-ricktest.service

  Description=Node.js Example Server
  #Requires=After=mysql.service       # Requires mysql service to run first

  # ExecStart=/usr/local/bin/node /opt/nodeserver/server.js
  ExecStart=/bin/node /home/rickatech/node/example.js
  RestartSec=10               # Restart service after 10 seconds if crashed
  StandardOutput=syslog       # Output to syslog
  StandardError=syslog        # Output to syslog
  # SyslogIdentifier=nodejs-example
  Environment=NODE_ENV=production PORT=1337


$ cat example.js 

  var http = require('http');

  http.createServer(function (req, res) {
	res.writeHead(200, {
		'Content-Type': 'text/plain'
	res.end('Hello World\n');
	}).listen(1337, "");

  console.log('Server running at');  

rickatech 2015-08


For small hosting environments without load balancers and such it can be handy to be able to run straight Apache with PHP and Node.js on the same server.  Using ProxyPass allows Apache to pass a particular URL path to a local service.  This means Node.js services can be run independently of Apache locally on different ports while Apache can unify them into a URL based directory that serves static web and dynamic PHP requests for directories not mapped to Node.js .  One thing to be mindful of is server sessions state - stay tuned for more on that.

<Directory /public/np1/site>
#   AllowOverride All
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted

VirtualHost *:80>
    DocumentRoot /public/np1/site
#   ErrorDocument 503 /maintenance.html

    ProxyRequests on
#   ProxyPass /maintenance.html !
    ProxyPass /np1/ http://localhost:1337/


circa 2011−12

[ reveal section ]  
zap technologies
tablet | printable