{"id":1818,"date":"2016-10-19T18:24:02","date_gmt":"2016-10-19T16:24:02","guid":{"rendered":"http:\/\/blog.rabahi.net\/?page_id=1818"},"modified":"2016-10-19T18:24:02","modified_gmt":"2016-10-19T16:24:02","slug":"srv-nodejs","status":"publish","type":"page","link":"https:\/\/blog.rabahi.net\/?page_id=1818","title":{"rendered":"srv-nodejs"},"content":{"rendered":"<h1>Prerequiste<\/h1>\n<p>I assume that you have a Centos installation.<\/p>\n<h1>Installation<\/h1>\n<p>You can copy\/paste this script and use it to configure automatically your server.<\/p>\n<pre class=\"bash\" style=\"font-family:monospace;\"><ol><li style=\"background: #fcfcfc;\"><div style=\"font-size: 12px;\"><span style=\"color: #666666; font-style: italic;\">#!\/bin\/bash<\/span><\/div><\/li><li style=\"background: #f0f0f0;\"><div style=\"font-size: 12px;\">&nbsp;<\/div><\/li><li style=\"background: #fcfcfc;\"><div style=\"font-size: 12px;\"><span style=\"color: #7a0874; font-weight: bold;\">echo<\/span> <span style=\"color: #ff0000;\">&quot;install prerequistes&quot;<\/span><\/div><\/li><li style=\"background: #f0f0f0;\"><div style=\"font-size: 12px;\">dnf <span style=\"color: #660033;\">-y<\/span> <span style=\"color: #c20cb9; font-weight: bold;\">install<\/span> nodejs<\/div><\/li><li style=\"background: #fcfcfc;\"><div style=\"font-size: 12px;\">&nbsp;<\/div><\/li><li style=\"background: #f0f0f0;\"><div style=\"font-size: 12px;\"><span style=\"color: #7a0874; font-weight: bold;\">echo<\/span> <span style=\"color: #ff0000;\">&quot;create working directory&quot;<\/span><\/div><\/li><li style=\"background: #fcfcfc;\"><div style=\"font-size: 12px;\"><span style=\"color: #c20cb9; font-weight: bold;\">mkdir<\/span> <span style=\"color: #660033;\">-p<\/span> <span style=\"color: #000000; font-weight: bold;\">\/<\/span>var<span style=\"color: #000000; font-weight: bold;\">\/<\/span>www<span style=\"color: #000000; font-weight: bold;\">\/<\/span>nodejs<\/div><\/li><li style=\"background: #f0f0f0;\"><div style=\"font-size: 12px;\">&nbsp;<\/div><\/li><li style=\"background: #fcfcfc;\"><div style=\"font-size: 12px;\"><span style=\"color: #7a0874; font-weight: bold;\">echo<\/span> <span style=\"color: #ff0000;\">&quot;create nodejs server&quot;<\/span><\/div><\/li><li style=\"background: #f0f0f0;\"><div style=\"font-size: 12px;\"><span style=\"color: #c20cb9; font-weight: bold;\">cat<\/span> <span style=\"color: #000000; font-weight: bold;\">&gt;<\/span> <span style=\"color: #000000; font-weight: bold;\">\/<\/span>var<span style=\"color: #000000; font-weight: bold;\">\/<\/span>www<span style=\"color: #000000; font-weight: bold;\">\/<\/span>nodejs<span style=\"color: #000000; font-weight: bold;\">\/<\/span>server.js <span style=\"color: #000000; font-weight: bold;\">&lt;&lt;<\/span> <span style=\"color: #ff0000;\">&quot;EOF&quot;<\/span><\/div><\/li><li style=\"background: #fcfcfc;\"><div style=\"font-size: 12px;\">var http = require<span style=\"color: #7a0874; font-weight: bold;\">&#40;<\/span><span style=\"color: #ff0000;\">'http'<\/span><span style=\"color: #7a0874; font-weight: bold;\">&#41;<\/span>;<\/div><\/li><li style=\"background: #f0f0f0;\"><div style=\"font-size: 12px;\">&nbsp;<\/div><\/li><li style=\"background: #fcfcfc;\"><div style=\"font-size: 12px;\">&nbsp;<\/div><\/li><li style=\"background: #f0f0f0;\"><div style=\"font-size: 12px;\">var server = http.createServer<span style=\"color: #7a0874; font-weight: bold;\">&#40;<\/span><span style=\"color: #000000; font-weight: bold;\">function<\/span><span style=\"color: #7a0874; font-weight: bold;\">&#40;<\/span>req, res<span style=\"color: #7a0874; font-weight: bold;\">&#41;<\/span> <span style=\"color: #7a0874; font-weight: bold;\">&#123;<\/span><\/div><\/li><li style=\"background: #fcfcfc;\"><div style=\"font-size: 12px;\">&nbsp;<\/div><\/li><li style=\"background: #f0f0f0;\"><div style=\"font-size: 12px;\">  res.writeHead<span style=\"color: #7a0874; font-weight: bold;\">&#40;<\/span><span style=\"color: #000000;\">200<\/span><span style=\"color: #7a0874; font-weight: bold;\">&#41;<\/span>;<\/div><\/li><li style=\"background: #fcfcfc;\"><div style=\"font-size: 12px;\">&nbsp;<\/div><\/li><li style=\"background: #f0f0f0;\"><div style=\"font-size: 12px;\">  res.end<span style=\"color: #7a0874; font-weight: bold;\">&#40;<\/span><span style=\"color: #ff0000;\">'Hello World !!'<\/span><span style=\"color: #7a0874; font-weight: bold;\">&#41;<\/span>;<\/div><\/li><li style=\"background: #fcfcfc;\"><div style=\"font-size: 12px;\">&nbsp;<\/div><\/li><li style=\"background: #f0f0f0;\"><div style=\"font-size: 12px;\"><span style=\"color: #7a0874; font-weight: bold;\">&#125;<\/span><span style=\"color: #7a0874; font-weight: bold;\">&#41;<\/span>;<\/div><\/li><li style=\"background: #fcfcfc;\"><div style=\"font-size: 12px;\">&nbsp;<\/div><\/li><li style=\"background: #f0f0f0;\"><div style=\"font-size: 12px;\">server.listen<span style=\"color: #7a0874; font-weight: bold;\">&#40;<\/span><span style=\"color: #000000;\">4587<\/span><span style=\"color: #7a0874; font-weight: bold;\">&#41;<\/span>;<\/div><\/li><li style=\"background: #fcfcfc;\"><div style=\"font-size: 12px;\">&nbsp;<\/div><\/li><li style=\"background: #f0f0f0;\"><div style=\"font-size: 12px;\">EOF<\/div><\/li><li style=\"background: #fcfcfc;\"><div style=\"font-size: 12px;\">&nbsp;<\/div><\/li><li style=\"background: #f0f0f0;\"><div style=\"font-size: 12px;\">&nbsp;<\/div><\/li><li style=\"background: #fcfcfc;\"><div style=\"font-size: 12px;\"><span style=\"color: #7a0874; font-weight: bold;\">echo<\/span> <span style=\"color: #ff0000;\">&quot;create service&quot;<\/span><\/div><\/li><li style=\"background: #f0f0f0;\"><div style=\"font-size: 12px;\"><span style=\"color: #c20cb9; font-weight: bold;\">cat<\/span> <span style=\"color: #000000; font-weight: bold;\">&gt;<\/span> <span style=\"color: #000000; font-weight: bold;\">\/<\/span>etc<span style=\"color: #000000; font-weight: bold;\">\/<\/span>systemd<span style=\"color: #000000; font-weight: bold;\">\/<\/span>system<span style=\"color: #000000; font-weight: bold;\">\/<\/span>myNodeJsService.service <span style=\"color: #000000; font-weight: bold;\">&lt;&lt;<\/span> <span style=\"color: #ff0000;\">&quot;EOF&quot;<\/span><\/div><\/li><li style=\"background: #fcfcfc;\"><div style=\"font-size: 12px;\"><span style=\"color: #7a0874; font-weight: bold;\">[<\/span>Unit<span style=\"color: #7a0874; font-weight: bold;\">]<\/span><\/div><\/li><li style=\"background: #f0f0f0;\"><div style=\"font-size: 12px;\"><span style=\"color: #007800;\">Description<\/span>=my node.js service<\/div><\/li><li style=\"background: #fcfcfc;\"><div style=\"font-size: 12px;\">&nbsp;<\/div><\/li><li style=\"background: #f0f0f0;\"><div style=\"font-size: 12px;\"><span style=\"color: #7a0874; font-weight: bold;\">[<\/span>Install<span style=\"color: #7a0874; font-weight: bold;\">]<\/span><\/div><\/li><li style=\"background: #fcfcfc;\"><div style=\"font-size: 12px;\"><span style=\"color: #007800;\">WantedBy<\/span>=multi-user.target<\/div><\/li><li style=\"background: #f0f0f0;\"><div style=\"font-size: 12px;\">&nbsp;<\/div><\/li><li style=\"background: #fcfcfc;\"><div style=\"font-size: 12px;\"><span style=\"color: #7a0874; font-weight: bold;\">[<\/span>Service<span style=\"color: #7a0874; font-weight: bold;\">]<\/span><\/div><\/li><li style=\"background: #f0f0f0;\"><div style=\"font-size: 12px;\"><span style=\"color: #007800;\">ExecStart<\/span>=<span style=\"color: #000000; font-weight: bold;\">\/<\/span>usr<span style=\"color: #000000; font-weight: bold;\">\/<\/span>bin<span style=\"color: #000000; font-weight: bold;\">\/<\/span>node <span style=\"color: #000000; font-weight: bold;\">\/<\/span>var<span style=\"color: #000000; font-weight: bold;\">\/<\/span>www<span style=\"color: #000000; font-weight: bold;\">\/<\/span>nodejs<span style=\"color: #000000; font-weight: bold;\">\/<\/span>server.js<\/div><\/li><li style=\"background: #fcfcfc;\"><div style=\"font-size: 12px;\"><span style=\"color: #007800;\">Restart<\/span>=on-success<\/div><\/li><li style=\"background: #f0f0f0;\"><div style=\"font-size: 12px;\"><span style=\"color: #007800;\">StandardOutput<\/span>=syslog<\/div><\/li><li style=\"background: #fcfcfc;\"><div style=\"font-size: 12px;\"><span style=\"color: #007800;\">StandardError<\/span>=syslog<\/div><\/li><li style=\"background: #f0f0f0;\"><div style=\"font-size: 12px;\"><span style=\"color: #007800;\">WorkingDirectory<\/span>=<span style=\"color: #000000; font-weight: bold;\">\/<\/span>var<span style=\"color: #000000; font-weight: bold;\">\/<\/span>www<span style=\"color: #000000; font-weight: bold;\">\/<\/span>nodejs<\/div><\/li><li style=\"background: #fcfcfc;\"><div style=\"font-size: 12px;\"><span style=\"color: #007800;\">Type<\/span>=simple<\/div><\/li><li style=\"background: #f0f0f0;\"><div style=\"font-size: 12px;\"><span style=\"color: #007800;\">User<\/span>=root<\/div><\/li><li style=\"background: #fcfcfc;\"><div style=\"font-size: 12px;\"><span style=\"color: #007800;\">Group<\/span>=root<\/div><\/li><li style=\"background: #f0f0f0;\"><div style=\"font-size: 12px;\"><span style=\"color: #007800;\">KillMode<\/span>=process<\/div><\/li><li style=\"background: #fcfcfc;\"><div style=\"font-size: 12px;\"><span style=\"color: #007800;\">PrivateTmp<\/span>=<span style=\"color: #c20cb9; font-weight: bold;\">true<\/span><\/div><\/li><li style=\"background: #f0f0f0;\"><div style=\"font-size: 12px;\">&nbsp;<\/div><\/li><li style=\"background: #fcfcfc;\"><div style=\"font-size: 12px;\">EOF<\/div><\/li><li style=\"background: #f0f0f0;\"><div style=\"font-size: 12px;\">&nbsp;<\/div><\/li><li style=\"background: #fcfcfc;\"><div style=\"font-size: 12px;\">&nbsp;<\/div><\/li><li style=\"background: #f0f0f0;\"><div style=\"font-size: 12px;\">systemctl <span style=\"color: #7a0874; font-weight: bold;\">enable<\/span> myNodeJsService.service<\/div><\/li><li style=\"background: #fcfcfc;\"><div style=\"font-size: 12px;\">systemctl start myNodeJsService.service<\/div><\/li><li style=\"background: #f0f0f0;\"><div style=\"font-size: 12px;\">&nbsp;<\/div><\/li><\/ol><\/pre>\n<p>That&#8217;s all \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Prerequiste I assume that you have a Centos installation. Installation You can copy\/paste this script and use it to configure automatically your server. That&#8217;s all \ud83d\ude42<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":679,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1818","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages\/1818","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1818"}],"version-history":[{"count":1,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages\/1818\/revisions"}],"predecessor-version":[{"id":1819,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages\/1818\/revisions\/1819"}],"up":[{"embeddable":true,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages\/679"}],"wp:attachment":[{"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1818"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}