Difference between revisions of "NodeJS"
(Add intro paragraph and link to nodejs.org) |
|||
(14 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
− | {{ | + | {{Note box|Please note that Nodejs is available via [[Software_collections|Software Collections]], which is the recommended way of using Nodejs on Koozali SME Server.}} |
+ | |||
+ | |||
Node.js® is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. | Node.js® is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. | ||
http://nodejs.org/ | http://nodejs.org/ | ||
+ | = For SME 8= | ||
+ | {{Level|Advanced}} | ||
+ | {{Warning box|This procedure requires installation of gcc and could significantly compromise your server's security.<br />Thorough understanding of linux system management is required.<br /><br /><b>Proceed at your own risk</b>}} | ||
+ | |||
==Prerequesites== | ==Prerequesites== | ||
Line 8: | Line 14: | ||
* git and g++ | * git and g++ | ||
yum -y install git gcc-c++ | yum -y install git gcc-c++ | ||
+ | |||
==Install== | ==Install== | ||
Line 22: | Line 29: | ||
make install | make install | ||
− | == | + | |
− | RELEASE=$(curl -s http://nodejs.org/download/ |grep Current\ version |awk -F"[><]" '{print $5}') | + | ===Updating=== |
+ | NodeJS should be recompiled if the package itself or any of its dependencies is updated. | ||
+ | |||
+ | NodeJS 1.7 dependencies include: | ||
+ | * openssl-devel | ||
+ | * v8-devel | ||
+ | * zlib-devel | ||
+ | |||
+ | The commands below will identify the latest release of nodejs, then download, recompile, and install: | ||
+ | RELEASE=$(curl -s -L http://nodejs.org/download/ |grep Current\ version |awk -F"[><]" '{print $5}') | ||
cd /var/git/node | cd /var/git/node | ||
git reset --hard | git reset --hard | ||
git pull origin $RELEASE-release | git pull origin $RELEASE-release | ||
+ | # | ||
+ | # recompile and install | ||
+ | # | ||
+ | export PYTHON=/usr/local/bin/python2.7 | ||
+ | $PYTHON ./configure | ||
+ | make | ||
+ | make install | ||
+ | |||
+ | = For SME 9 = | ||
+ | On SME 9, you can install a reasonably recent version of NodeJS from the EPEL repository: | ||
+ | * Add the epel repository to the configuration db using the SME 9 instructions from [[Epel]] | ||
+ | * Update the yum configuration file using | ||
+ | signal-event yum-modify | ||
+ | * Install NodeJS | ||
+ | yum --enablerepo=epel install nodejs | ||
+ | This will install nodejs plus c-ares19, http-parser, libuv and v8 from the epel repo, plus libicu from the base repo. | ||
+ | |||
+ | |||
+ | ==Updating== | ||
+ | * Update using | ||
+ | yum --enablerepo=epel update nodejs c-ares19 http-parser libuv v8 | ||
+ | * NodeJS updates are released every 3 - 12 weeks; check for updates regularly. | ||
+ | <headertabs /> | ||
+ | |||
+ | |||
+ | ==Node Repo== | ||
+ | |||
+ | You can install the latest versions of node direct from their repository. | ||
+ | |||
+ | See this page for to help add the repos to SME: | ||
+ | https://wiki.contribs.org/Extrarepositories | ||
+ | |||
+ | yum install smeserver-extrarepositories-node | ||
+ | signal-event yum-modify | ||
+ | config set UnsavedChanges no | ||
+ | |||
+ | This will add a set of Node repos to your yum_repositories database. | ||
+ | Node v4-v11 | ||
+ | |||
+ | You can now install a version of node from the repo eg: | ||
+ | |||
+ | yum --enablerepo=node8 install nodejs8.9.4 | ||
+ | |||
+ | yum --enablerepo=node11 install nodejs11.8.0 | ||
+ | |||
+ | Remember that this installs the base RPM but you can switch versions using the 'n' version manager | ||
+ | |||
+ | npm install -g n | ||
+ | |||
+ | For help: | ||
+ | n -h | ||
+ | |||
+ | For available versions: | ||
+ | n ls | ||
==Test== | ==Test== | ||
Line 32: | Line 102: | ||
+ | == Port Redirect for each application== | ||
+ | |||
+ | {{Note box|| This is still work in progress and may not work correctly}} | ||
+ | |||
+ | Each Node application you build must run on a different port. This can be configured in app.js | ||
+ | |||
+ | If you want to redirect an external URL to the app port using a reverse proxy you can do the following | ||
+ | |||
+ | a) create that external domain on SME web interface for domain as '''www.your.externaldomain.tld''' | ||
+ | |||
+ | b) create a new variable (NodePort) to specify that port | ||
+ | db domains setprop '''www.your.externadomain.tld''' NodePort 3003 | ||
+ | |||
+ | c) use a custom fragment template file '''/etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf/VirtualHosts/27ProxyNodeJS''' with: | ||
+ | <nowiki> | ||
+ | { | ||
+ | use esmith::DomainsDB; | ||
+ | my $domains = esmith::DomainsDB->open_ro; | ||
+ | |||
+ | my $nodeport = $domains->get_prop($virtualHost, "NodePort") || "disabled"; | ||
+ | return " # skipping NodeJS redirect - no NodePort parameter\n" unless not $nodeport eq "disabled"; | ||
+ | |||
+ | $OUT .= " # NodeJS port redirect\n" unless $nodeport eq 'disabled'; | ||
+ | $OUT .= " ProxyPreserveHost On\n" unless $nodeport eq 'disabled'; | ||
+ | $OUT .= " ProxyRequests Off\n" unless $nodeport eq 'disabled'; | ||
+ | $OUT .= " ProxyPass / http://localhost:$nodeport/\n" unless $nodeport eq 'disabled'; | ||
+ | $OUT .= " ProxyPassReverse / http://localhost:$nodeport/\n" unless $nodeport eq 'disabled'; | ||
+ | } | ||
+ | </nowiki> | ||
+ | |||
+ | Now just expand templates and restart | ||
+ | expand-template /etc/httpd/conf/httpd.conf | ||
+ | /etc/init.d/httpd-e-smith restart | ||
+ | |||
+ | You should be able to access your app externally using '''http://www.your.externaldomain.tld''' | ||
+ | |||
+ | It's possible to access using SME with one LetsEncrypt certificate by directory/port | ||
---- | ---- | ||
[[Category:Howto]] | [[Category:Howto]] |
Latest revision as of 15:37, 29 January 2019
Node.js® is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.
Prerequesites
- Requires Python 2.7 installed as described in Python Altinstall
- git and g++
yum -y install git gcc-c++
Install
mkdir -p /var/git cd /var/git RELEASE=$(curl -s http://nodejs.org/download/ |grep Current\ version |awk -F"[><]" '{print $5}') git clone https://github.com/joyent/node.git cd /var/git/node git reset --hard git checkout $RELEASE export PYTHON=/usr/local/bin/python2.7 $PYTHON ./configure make make install
Updating
NodeJS should be recompiled if the package itself or any of its dependencies is updated.
NodeJS 1.7 dependencies include:
- openssl-devel
- v8-devel
- zlib-devel
The commands below will identify the latest release of nodejs, then download, recompile, and install:
RELEASE=$(curl -s -L http://nodejs.org/download/ |grep Current\ version |awk -F"[><]" '{print $5}') cd /var/git/node git reset --hard git pull origin $RELEASE-release # # recompile and install # export PYTHON=/usr/local/bin/python2.7 $PYTHON ./configure make make install
On SME 9, you can install a reasonably recent version of NodeJS from the EPEL repository:
- Add the epel repository to the configuration db using the SME 9 instructions from Epel
- Update the yum configuration file using
signal-event yum-modify
- Install NodeJS
yum --enablerepo=epel install nodejs
This will install nodejs plus c-ares19, http-parser, libuv and v8 from the epel repo, plus libicu from the base repo.
Updating
- Update using
yum --enablerepo=epel update nodejs c-ares19 http-parser libuv v8
- NodeJS updates are released every 3 - 12 weeks; check for updates regularly.
Node Repo
You can install the latest versions of node direct from their repository.
See this page for to help add the repos to SME: https://wiki.contribs.org/Extrarepositories
yum install smeserver-extrarepositories-node signal-event yum-modify config set UnsavedChanges no
This will add a set of Node repos to your yum_repositories database. Node v4-v11
You can now install a version of node from the repo eg:
yum --enablerepo=node8 install nodejs8.9.4
yum --enablerepo=node11 install nodejs11.8.0
Remember that this installs the base RPM but you can switch versions using the 'n' version manager
npm install -g n
For help:
n -h
For available versions: n ls
Test
node -v
Port Redirect for each application
Each Node application you build must run on a different port. This can be configured in app.js
If you want to redirect an external URL to the app port using a reverse proxy you can do the following
a) create that external domain on SME web interface for domain as www.your.externaldomain.tld
b) create a new variable (NodePort) to specify that port
db domains setprop www.your.externadomain.tld NodePort 3003
c) use a custom fragment template file /etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf/VirtualHosts/27ProxyNodeJS with:
{ use esmith::DomainsDB; my $domains = esmith::DomainsDB->open_ro; my $nodeport = $domains->get_prop($virtualHost, "NodePort") || "disabled"; return " # skipping NodeJS redirect - no NodePort parameter\n" unless not $nodeport eq "disabled"; $OUT .= " # NodeJS port redirect\n" unless $nodeport eq 'disabled'; $OUT .= " ProxyPreserveHost On\n" unless $nodeport eq 'disabled'; $OUT .= " ProxyRequests Off\n" unless $nodeport eq 'disabled'; $OUT .= " ProxyPass / http://localhost:$nodeport/\n" unless $nodeport eq 'disabled'; $OUT .= " ProxyPassReverse / http://localhost:$nodeport/\n" unless $nodeport eq 'disabled'; }
Now just expand templates and restart
expand-template /etc/httpd/conf/httpd.conf /etc/init.d/httpd-e-smith restart
You should be able to access your app externally using http://www.your.externaldomain.tld
It's possible to access using SME with one LetsEncrypt certificate by directory/port