{"id":1624,"date":"2017-09-05T14:52:25","date_gmt":"2017-09-05T12:52:25","guid":{"rendered":"https:\/\/blog.alwaysdata.com\/?p=1624"},"modified":"2020-04-17T15:21:28","modified_gmt":"2020-04-17T13:21:28","slug":"heberger-une-application-node-js-chez-alwaysdata","status":"publish","type":"post","link":"https:\/\/blog.alwaysdata.com\/fr\/2017\/09\/05\/heberger-une-application-node-js-chez-alwaysdata\/","title":{"rendered":"H\u00e9berger une application Node.js chez alwaysdata"},"content":{"rendered":"<p>Notre annonce du <a href=\"https:\/\/blog.alwaysdata.com\/fr\/2017\/08\/28\/nouveaux-langages-cest-parti\/\">support de nouveaux langages<\/a> a&nbsp;suscit\u00e9 de l\u2019enthousiasme et plusieurs clients font d\u00e9j\u00e0 tourner des applications Node.js.&nbsp;Nous continuons donc sur notre lanc\u00e9e avec ce billet qui se concentre, justement, sur <a href=\"https:\/\/nodejs.org\">Node.js<\/a>.<\/p>\n<h3>Un langage majeur<\/h3>\n<p>Comme promis la semaine derni\u00e8re, nous avons&nbsp;une surprise&nbsp;: <a href=\"https:\/\/help.alwaysdata.com\/fr\/langages\/nodejs\">Node.js<\/a> devient le quatri\u00e8me langage <em>majeur<\/em> support\u00e9 chez alwaysdata, apr\u00e8s <a href=\"https:\/\/help.alwaysdata.com\/fr\/langages\/php\">PHP<\/a>, <a href=\"https:\/\/help.alwaysdata.com\/fr\/langages\/python\">Python<\/a> et <a href=\"https:\/\/help.alwaysdata.com\/fr\/langages\/ruby\">Ruby<\/a>. Qu\u2019est-ce que cela veut&nbsp;dire&nbsp;?<\/p>\n<p>D\u2019une certaine mani\u00e8re, on pourrait dire que Node.js est support\u00e9 depuis longtemps chez&nbsp;alwaysdata&nbsp;: il \u00ab&nbsp;suffisait&nbsp;\u00bb de t\u00e9l\u00e9charger sur son compte l\u2019interpr\u00e9teur depuis&nbsp;<a href=\"https:\/\/nodejs.org\/en\/download\/\">le site officiel<\/a>&nbsp;pour faire tourner du Node.js. C\u00f4t\u00e9 web, il fallait toutefois&nbsp;ruser pour faire tourner son application, par exemple en utilisant PHP&nbsp;en reverse proxy. Faisable\u2026 mais complexe.<\/p>\n<p>Devenir un langage&nbsp;<em>majeur<\/em>, cela implique&nbsp;:<\/p>\n<ul>\n<li>que nous avons pr\u00e9install\u00e9 l\u2019interpr\u00e9teur, et qu\u2019il est m\u00eame possible de choisir parmi plusieurs versions de l\u2019interpr\u00e9teur (via le menu <em>Environnement<\/em> de l\u2019administration alwaysdata). Aujourd\u2019hui, Node.js est disponible en versions 6.x (6.11.2) et 8.x (8.4.0) ;<\/li>\n<li>que de nouvelles versions de l\u2019interpr\u00e9teur seront install\u00e9es r\u00e9guli\u00e8rement, pas uniquement des mises \u00e0&nbsp;jour de s\u00e9curit\u00e9&nbsp;;<\/li>\n<li>qu\u2019il est facile de d\u00e9ployer une application web dans ce langage&nbsp;;<\/li>\n<li>qu\u2019il est facile d\u2019installer des d\u00e9pendances externes, en utilisant le gestionnaire de&nbsp;paquets officiel en SSH. Pour Node.js, c\u2019est&nbsp;<a href=\"https:\/\/www.npmjs.com\/\"><em>npm<\/em><\/a>,<em>&nbsp;<\/em>qui est \u00e9galement pr\u00e9install\u00e9.<\/li>\n<\/ul>\n<p>Nous avons donc rajout\u00e9 un nouveau type de site,&nbsp;<em>Node.js<\/em>. Il est similaire au type&nbsp;<em>Programme utilisateur<\/em>\u200a\u2014\u200acar les applications Node.js int\u00e8grent leur propre serveur HTTP et n\u2019ont pas besoin de couche interm\u00e9diaire\u200a\u2014\u200a\u00e0&nbsp;une diff\u00e9rence pr\u00e8s&nbsp;: il est possible de sp\u00e9cifier une version de Node.js explicite pour ce site. Et donc d\u2019avoir plusieurs sites distincts utilisant des versions de Node.js diff\u00e9rentes.<\/p>\n<h3>Exemple&nbsp;: d\u00e9ployer une application Express<\/h3>\n<p><a href=\"http:\/\/expressjs.com\/\">Express<\/a> est l\u2019un des frameworks Node.js les plus&nbsp;connus. Voyons comme h\u00e9berger une application d\u00e9velopp\u00e9e avec.<\/p>\n<ul>\n<li>Tout d\u2019abord, nous devons installer Express. Suivons la <a href=\"http:\/\/expressjs.com\/en\/starter\/installing.html\">documentation officielle<\/a>, en ex\u00e9cutant les commandes en SSH (et en acceptant&nbsp;tout par d\u00e9faut)&nbsp;:<\/li>\n<\/ul>\n<pre class=\"lang:sh decode:true\" title=\"Installation d'Express\">$ mkdir myapp\n$ cd myapp\n$ npm init\n$ npm install express --save\n<\/pre>\n<ul>\n<li>Cr\u00e9ons ensuite le fichier <em>app.js<\/em>, toujours en suivant la <a href=\"http:\/\/expressjs.com\/en\/starter\/hello-world.html\">documentation d\u2019Express<\/a>. On modifie l\u00e9g\u00e8rement&nbsp;le code pour que l\u2019application \u00e9coute sur l\u2019IP et le port qui seront donn\u00e9s en variables d\u2019environnement&nbsp;:<\/li>\n<\/ul>\n<pre class=\"lang:js decode:true  \" title=\"Code de l'application\">const express = require('express')\nconst app = express()\n\napp.get('\/', function (req, res) {\n  res.send('Hello World!')\n})\n\napp.listen(process.env.PORT, process.env.IP, function () {\n  console.log('Example app started!')\n})<\/pre>\n<ul>\n<li>Enfin, dans l\u2019administration alwaysdata, cr\u00e9ons un site de type&nbsp;<em>Node.js<\/em>, en indiquant comme commande&nbsp;:<\/li>\n<\/ul>\n<pre class=\"lang:default decode:true\" title=\"Commande du site\">node ~\/myapp\/app.js<\/pre>\n<p>Le tour est jou\u00e9&nbsp;: notre petite application Express est bien joignable&nbsp;!<\/p>\n<p>Prochain langage au programme, pour le second billet de notre s\u00e9rie&nbsp;: <a href=\"https:\/\/www.lua.org\/\">Lua<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Notre annonce du support de nouveaux langages a&nbsp;suscit\u00e9 de l\u2019enthousiasme et plusieurs clients font d\u00e9j\u00e0 tourner des applications Node.js.&nbsp;Nous continuons donc sur notre lanc\u00e9e avec \u2026 <a class=\"read-more\" href=\"https:\/\/blog.alwaysdata.com\/fr\/2017\/09\/05\/heberger-une-application-node-js-chez-alwaysdata\/\">Keep reading<\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"wp_typography_post_enhancements_disabled":false,"footnotes":""},"categories":[1],"tags":[118,105],"class_list":["post-1624","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-languages","tag-node-js"],"acf":[],"_links":{"self":[{"href":"https:\/\/blog.alwaysdata.com\/fr\/wp-json\/wp\/v2\/posts\/1624","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.alwaysdata.com\/fr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.alwaysdata.com\/fr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.alwaysdata.com\/fr\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.alwaysdata.com\/fr\/wp-json\/wp\/v2\/comments?post=1624"}],"version-history":[{"count":0,"href":"https:\/\/blog.alwaysdata.com\/fr\/wp-json\/wp\/v2\/posts\/1624\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.alwaysdata.com\/fr\/wp-json\/wp\/v2\/media?parent=1624"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.alwaysdata.com\/fr\/wp-json\/wp\/v2\/categories?post=1624"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.alwaysdata.com\/fr\/wp-json\/wp\/v2\/tags?post=1624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}