<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ca">
	<id>http://wiki.joanillo.org/index.php?action=history&amp;feed=atom&amp;title=Comunitats%2C_prov%C3%ADncies%2C_municipis._Migraci%C3%B3_a_Node.js</id>
	<title>Comunitats, províncies, municipis. Migració a Node.js - Historial de revisió</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.joanillo.org/index.php?action=history&amp;feed=atom&amp;title=Comunitats%2C_prov%C3%ADncies%2C_municipis._Migraci%C3%B3_a_Node.js"/>
	<link rel="alternate" type="text/html" href="http://wiki.joanillo.org/index.php?title=Comunitats,_prov%C3%ADncies,_municipis._Migraci%C3%B3_a_Node.js&amp;action=history"/>
	<updated>2026-09-22T22:07:04Z</updated>
	<subtitle>Historial de revisió per a aquesta pàgina del wiki</subtitle>
	<generator>MediaWiki 1.34.2</generator>
	<entry>
		<id>http://wiki.joanillo.org/index.php?title=Comunitats,_prov%C3%ADncies,_municipis._Migraci%C3%B3_a_Node.js&amp;diff=298547&amp;oldid=prev</id>
		<title>Joan a 15:24, 22 feb 2022</title>
		<link rel="alternate" type="text/html" href="http://wiki.joanillo.org/index.php?title=Comunitats,_prov%C3%ADncies,_municipis._Migraci%C3%B3_a_Node.js&amp;diff=298547&amp;oldid=prev"/>
		<updated>2022-02-22T15:24:36Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ca&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Versió més antiga&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revisió del 15:24, 22 feb 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l4&quot; &gt;Línia 4:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Línia 4:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=Referències=&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=Referències=&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Hem vist Node.js a teoria:&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Hem vist Node.js a teoria:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;*&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;http://wiki.joanillo.org/index.php/Introducci%C3%B3_a_Node&lt;/del&gt;.js&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;*&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;[[Introducció a Node&lt;/ins&gt;.js&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Durant el desenvolupament de la pràctica el professor s'ha trobat el típic problema de ''Control d'accés HTTP (CORS)'', que s'ha pogut solucionar fàcilment:&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;*https://stackoverflow.com/questions/18310394/no-access-control-allow-origin-node-apache-port-issue&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=Desenvolupament=&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=Desenvolupament=&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l12&quot; &gt;Línia 12:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Línia 10:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Servidor http amb Node.js. Codi mínim==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Servidor http amb Node.js. Codi mínim==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;El codi mínim per accedir a la base de dades de municipis:&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;El codi mínim per accedir a la base de dades de municipis:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;script '''node_http_server_simple.js''':&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;script '''node_http_server_simple.js''':&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;// &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;el servidor web implementat amb node ha d'estar arrencat&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;//&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;test:&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;// /home/joan/node-v9.6.1-linux-x64/bin/node /home/joan/M06_WEC_1718/html/UF4/municipis_node/node_http_server.js&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;// Are you running your script from the same directory you ran npm install mysql? &lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;//important! npm install request&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;//important! npm install url&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;//http://localhost:8080/search_prov?id_com=2&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;//http://localhost:8080/search_prov?id_com=2&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;var http = require('http');&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;var http = require('http');&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;//&lt;/del&gt;var mysql = require('&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;mysql&lt;/del&gt;');&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;var mysql = require('&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;mysql2&lt;/ins&gt;');&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;var mysql = require('/home/joan/node-v9.6.1-linux-x64/bin/node_modules/mysql');&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;var request = require('request'); //&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;npm install &lt;/ins&gt;request&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;//&lt;/del&gt;var request = require('&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;/home/joan/node-v9.6.1-linux-x64/bin/node_modules/&lt;/del&gt;request');&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;var url = require('url'); &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;//no cal instal·lar aquest mòdul&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;var request = require('/home&lt;/del&gt;/&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;joan/node-v9.6.1-linux-x64/bin/node_modules&lt;/del&gt;/request&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;');&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;var url = require('&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;/home/joan/node-v9.6.1-linux-x64/bin/node_modules/&lt;/del&gt;url');&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l71&quot; &gt;Línia 71:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Línia 61:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Hem d'arrencar el servidor, i des del navegador web podem accedir a la informació de les províncies. Per ex:&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Hem d'arrencar el servidor, i des del navegador web podem accedir a la informació de les províncies. Per ex:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;*http://localhost:8080/search_prov?id_com=7&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;*http://localhost:8080/search_prov?id_com=7&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Hem hagut d'&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;instal.lar &lt;/del&gt;els paquets '''request''' i '''url''' per tal de poder accedir a la informació del paràmetre que passem per GET (''id_com=7)&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Hem hagut d'&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;instal·lar &lt;/ins&gt;els paquets '''request''' i '''url''' per tal de poder accedir a la informació del paràmetre que passem per GET (''id_com=7)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;$ npm install request&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;$ npm install request&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;$ npm install url&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;$ npm install url&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/pre&amp;gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;També hi ha hagut una mica d'embolic amb el directori on anem a busca els paquets ''npm''. Si el script que executem no està en el mateix directori que el binari ''node'' (d'on penja la carpeta ''node_modules/''), una possible solució (no òptima?) és posar la ruta on anem a buscar el paquet:&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;pre&amp;gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;var request = require('/home/joan/node-v9.6.1-linux-x64/bin/node_modules/request');&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;var url = require('/home/joan/node-v9.6.1-linux-x64/bin/node_modules/url');&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;===Aplicació AJAX contra Node.js===&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;===Aplicació AJAX contra Node.js===&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l149&quot; &gt;Línia 149:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Línia 134:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   if (req.url.indexOf(&amp;quot;comunitats&amp;quot;)&amp;gt;=0) {&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   if (req.url.indexOf(&amp;quot;comunitats&amp;quot;)&amp;gt;=0) {&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     console.log(&amp;quot;COMUNITATS&amp;quot;);&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     console.log(&amp;quot;COMUNITATS&amp;quot;);&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;    //https://stackoverflow.com/questions/18310394/no-access-control-allow-origin-node-apache-port-issue&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;    // Website you wish to allow to connect&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;    //res.setHeader('Access-Control-Allow-Origin', 'http://localhost:8080'); //no funciona?&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     res.setHeader('Access-Control-Allow-Origin', '*'); //funciona&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     res.setHeader('Access-Control-Allow-Origin', '*'); //funciona&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;    //res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE'); // If needed&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;    //res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,contenttype'); // If needed&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;    //res.setHeader('Access-Control-Allow-Credentials', true); // If needed&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     res.setHeader(&amp;quot;Content-Type&amp;quot;, &amp;quot;text/html; charset=utf-8&amp;quot;);&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     res.setHeader(&amp;quot;Content-Type&amp;quot;, &amp;quot;text/html; charset=utf-8&amp;quot;);&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l166&quot; &gt;Línia 166:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Línia 145:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;         for (var i = 0; i &amp;lt; rows.length; i++) {&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;         for (var i = 0; i &amp;lt; rows.length; i++) {&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;           console.log(rows[i].comunitat);&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;           console.log(rows[i].comunitat);&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;          //res.write(rows[i].comunitat + '&amp;lt;br /&amp;gt;');&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;           res.write(&amp;quot;&amp;lt;option value=\&amp;quot;&amp;quot; + rows[i].id_com + &amp;quot;\&amp;quot;&amp;gt;&amp;quot; + rows[i].comunitat + &amp;quot;&amp;lt;/option&amp;gt;&amp;quot;);&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;           res.write(&amp;quot;&amp;lt;option value=\&amp;quot;&amp;quot; + rows[i].id_com + &amp;quot;\&amp;quot;&amp;gt;&amp;quot; + rows[i].comunitat + &amp;quot;&amp;lt;/option&amp;gt;&amp;quot;);&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;         };&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;         };&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l254&quot; &gt;Línia 254:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Línia 232:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Solució==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Solució==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Tens disponible el codi que s'ha comentat a classe, amb les tres versions:&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Tens disponible el codi que s'ha comentat a classe, amb les tres versions:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;*[[Fitxer:Municipis node.zip]] (actualitzat a &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;6 &lt;/del&gt;de &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;març &lt;/del&gt;de &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;2019&lt;/del&gt;)&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;*[[Fitxer:Municipis node.zip]] (actualitzat a &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;22 &lt;/ins&gt;de &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;febrer &lt;/ins&gt;de &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;2022&lt;/ins&gt;)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=Entrega=&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=Entrega=&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Els alumnes entregaran &lt;/del&gt;al Classroom &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;tots els fitxers generats (fitxers html)&lt;/del&gt;. &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;S'empaquetaran tots aquests fitxers i es pujaran &lt;/del&gt;al &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Schoology dins &lt;/del&gt;del &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;termini d'entrega &lt;/del&gt;de &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;la pràctica.&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Entregaràs &lt;/ins&gt;al Classroom &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;tot el projecte empaquetat en un zip&lt;/ins&gt;. &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Quan ho tinguis funcionant, ensenya-ho &lt;/ins&gt;al &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;professor, o sinó fes un screencast &lt;/ins&gt;del &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;funcionament &lt;/ins&gt;de &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;l&lt;/ins&gt;'&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;aplicatiu, comentant el resultat final i &lt;/ins&gt;les &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;parts més importants del codi&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Recorda la &lt;/del&gt;'&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;''normativa''' per entregar &lt;/del&gt;les &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;pràctiques al Schoology: [[ASIX-M10-UF2#Normativa_d.27entrega_de_les_pr.C3&lt;/del&gt;.&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;A0ctiques_al_Schoology]]&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{Autor}}, febrer &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;2018&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{Autor}}, febrer &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;2022&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;[[Categoria: INS Jaume Balmes]]&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;[[Categoria: Assignatura DAW-M06-WEC]]&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Joan</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.joanillo.org/index.php?title=Comunitats,_prov%C3%ADncies,_municipis._Migraci%C3%B3_a_Node.js&amp;diff=258272&amp;oldid=prev</id>
		<title>Joan: /* Solució */</title>
		<link rel="alternate" type="text/html" href="http://wiki.joanillo.org/index.php?title=Comunitats,_prov%C3%ADncies,_municipis._Migraci%C3%B3_a_Node.js&amp;diff=258272&amp;oldid=prev"/>
		<updated>2019-03-06T18:45:35Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Solució&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Pàgina nova&lt;/b&gt;&lt;/p&gt;&lt;div&gt;=Introducció=&lt;br /&gt;
En la pràctica anterior has fet una mini-aplicació per navegar per les comunitats, províncies i municipis de l'EE. Anem ara a canviar la tecnologia del servidor, i anem a fer les nostres crides AJAX contra un servidor Node.js. És a dir, farem servir Javascript tan en el cantó del client com en el cantó del servidor.&lt;br /&gt;
&lt;br /&gt;
=Referències=&lt;br /&gt;
Hem vist Node.js a teoria:&lt;br /&gt;
*http://wiki.joanillo.org/index.php/Introducci%C3%B3_a_Node.js&lt;br /&gt;
Durant el desenvolupament de la pràctica el professor s'ha trobat el típic problema de ''Control d'accés HTTP (CORS)'', que s'ha pogut solucionar fàcilment:&lt;br /&gt;
*https://stackoverflow.com/questions/18310394/no-access-control-allow-origin-node-apache-port-issue&lt;br /&gt;
&lt;br /&gt;
=Desenvolupament=&lt;br /&gt;
&lt;br /&gt;
==Servidor http amb Node.js. Codi mínim==&lt;br /&gt;
El codi mínim per accedir a la base de dades de municipis:&lt;br /&gt;
&lt;br /&gt;
script '''node_http_server_simple.js''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// el servidor web implementat amb node ha d'estar arrencat&lt;br /&gt;
// /home/joan/node-v9.6.1-linux-x64/bin/node /home/joan/M06_WEC_1718/html/UF4/municipis_node/node_http_server.js&lt;br /&gt;
// Are you running your script from the same directory you ran npm install mysql? &lt;br /&gt;
//important! npm install request&lt;br /&gt;
//important! npm install url&lt;br /&gt;
&lt;br /&gt;
//http://localhost:8080/search_prov?id_com=2&lt;br /&gt;
&lt;br /&gt;
var http = require('http');&lt;br /&gt;
//var mysql = require('mysql');&lt;br /&gt;
var mysql = require('/home/joan/node-v9.6.1-linux-x64/bin/node_modules/mysql');&lt;br /&gt;
//var request = require('/home/joan/node-v9.6.1-linux-x64/bin/node_modules/request');&lt;br /&gt;
var request = require('/home/joan/node-v9.6.1-linux-x64/bin/node_modules/request');&lt;br /&gt;
var url = require('/home/joan/node-v9.6.1-linux-x64/bin/node_modules/url');&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// Create a connection to MySql Server and Database&lt;br /&gt;
var connection = mysql.createConnection({&lt;br /&gt;
  host : 'localhost',&lt;br /&gt;
  port : 3306,&lt;br /&gt;
  database: 'municipis',&lt;br /&gt;
  user : 'alumne',&lt;br /&gt;
  password : 'keiL2lai',&lt;br /&gt;
  charset : 'utf8'&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// Create a simple Web Server to respond to requests&lt;br /&gt;
http.createServer(function(req, res){&lt;br /&gt;
  // RECEIVED A REQUEST!&lt;br /&gt;
  console.log(req.url);&lt;br /&gt;
&lt;br /&gt;
  res.setHeader(&amp;quot;Content-Type&amp;quot;, &amp;quot;text/html; charset=utf-8&amp;quot;);&lt;br /&gt;
  res.writeHeader(200);&lt;br /&gt;
&lt;br /&gt;
  var query = require('url').parse(req.url,true).query;&lt;br /&gt;
  var id_com = query.id_com;&lt;br /&gt;
  console.log(id_com);&lt;br /&gt;
&lt;br /&gt;
  connection.query(&amp;quot;SELECT id_prov,provincia from provincies where id_com=&amp;quot;+id_com, function(err, rows){&lt;br /&gt;
&lt;br /&gt;
  if(err != null) {&lt;br /&gt;
    res.end(&amp;quot;Query error:&amp;quot; + err);&lt;br /&gt;
  } else {&lt;br /&gt;
    for (var i = 0; i &amp;lt; rows.length; i++) {&lt;br /&gt;
      console.log(rows[i].provincia);&lt;br /&gt;
      res.write(rows[i].provincia + '&amp;lt;br /&amp;gt;');&lt;br /&gt;
    };&lt;br /&gt;
    res.end(&amp;quot;&amp;quot;); //important&lt;br /&gt;
  }&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
}).listen(8080);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Hem d'arrencar el servidor, i des del navegador web podem accedir a la informació de les províncies. Per ex:&lt;br /&gt;
*http://localhost:8080/search_prov?id_com=7&lt;br /&gt;
Hem hagut d'instal.lar els paquets '''request''' i '''url''' per tal de poder accedir a la informació del paràmetre que passem per GET (''id_com=7)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ npm install request&lt;br /&gt;
$ npm install url&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
També hi ha hagut una mica d'embolic amb el directori on anem a busca els paquets ''npm''. Si el script que executem no està en el mateix directori que el binari ''node'' (d'on penja la carpeta ''node_modules/''), una possible solució (no òptima?) és posar la ruta on anem a buscar el paquet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
var request = require('/home/joan/node-v9.6.1-linux-x64/bin/node_modules/request');&lt;br /&gt;
var url = require('/home/joan/node-v9.6.1-linux-x64/bin/node_modules/url');&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Aplicació AJAX contra Node.js===&lt;br /&gt;
Hem de modificar el nostre servidor per distingir si volem fer un llistat de les comunitats; volem llistar les províncies d'una comunitat; o volem llistar els municipis d'una província:&lt;br /&gt;
*http://localhost:8080/comunitats&lt;br /&gt;
*http://localhost:8080/search_prov?id_com=2&lt;br /&gt;
*http://localhost:8080/search_mun?id_prov=20&lt;br /&gt;
&lt;br /&gt;
Ho farem mirant la ''url'' del request:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if (req.url.indexOf(&amp;quot;comunitats&amp;quot;)&amp;gt;=0) {&lt;br /&gt;
   console.log(&amp;quot;COMUNITATS&amp;quot;);&lt;br /&gt;
   ...&lt;br /&gt;
} else if (req.url.indexOf(&amp;quot;search_prov&amp;quot;)&amp;gt;=0) {&lt;br /&gt;
   console.log(&amp;quot;PROVÍNCIES&amp;quot;);&lt;br /&gt;
   ...&lt;br /&gt;
} else if (req.url.indexOf(&amp;quot;search_mun&amp;quot;)&amp;gt;=0) {&lt;br /&gt;
   console.log(&amp;quot;MUNICIPIS&amp;quot;);&lt;br /&gt;
   ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ara ja podem adaptar el codi que tenim de la pràctica anterior per fer crides contra el servidor http implementat amb Node.js. Per exemple, quan carreguem l'aplicació (''body onload'') carregarem en una ''select box'' la llista de totes les comunitats.&lt;br /&gt;
&lt;br /&gt;
script '''index.html''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script&amp;gt;&lt;br /&gt;
function carregar_comunitats()&lt;br /&gt;
{&lt;br /&gt;
	var xmlhttp;&lt;br /&gt;
	var txt_opcions_comunitats;&lt;br /&gt;
	xmlhttp=new XMLHttpRequest();&lt;br /&gt;
	xmlhttp.onreadystatechange=function()&lt;br /&gt;
	{&lt;br /&gt;
		if (xmlhttp.readyState==4 &amp;amp;&amp;amp; xmlhttp.status==200)&lt;br /&gt;
		{&lt;br /&gt;
			txt_opcions_comunitats = xmlhttp.responseText;&lt;br /&gt;
			//alert(txt_opcions_comunitats);&lt;br /&gt;
			var comunitats = &amp;quot;&amp;quot;;&lt;br /&gt;
			comunitats = &amp;quot;&amp;lt;select name=\&amp;quot;comunitat\&amp;quot; onchange=\&amp;quot;canvi_comunitat(this.value)\&amp;quot;&amp;gt;&amp;quot;;&lt;br /&gt;
			comunitats += txt_opcions_comunitats;&lt;br /&gt;
			comunitats += &amp;quot;&amp;lt;/select&amp;gt;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
			document.getElementById('comunitats').innerHTML = comunitats;&lt;br /&gt;
		} else {&lt;br /&gt;
			document.getElementById('comunitats').innerHTML = &amp;quot;&amp;lt;img src=\&amp;quot;img/ajax_wait.gif\&amp;quot; /&amp;gt;&amp;quot;;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	xmlhttp.open(&amp;quot;GET&amp;quot;,&amp;quot;http://localhost:8080/comunitats&amp;quot;,true);&lt;br /&gt;
	xmlhttp.send();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I la cerca de les comunitats està implementada en el servidor Node.js de la següent manera:&lt;br /&gt;
&lt;br /&gt;
'''node_http_server.js''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
// Create a simple Web Server to respond to requests&lt;br /&gt;
http.createServer(function(req, res){&lt;br /&gt;
  // RECEIVED A REQUEST!&lt;br /&gt;
  console.log(req.url);&lt;br /&gt;
&lt;br /&gt;
  if (req.url.indexOf(&amp;quot;comunitats&amp;quot;)&amp;gt;=0) {&lt;br /&gt;
    console.log(&amp;quot;COMUNITATS&amp;quot;);&lt;br /&gt;
    //https://stackoverflow.com/questions/18310394/no-access-control-allow-origin-node-apache-port-issue&lt;br /&gt;
    // Website you wish to allow to connect&lt;br /&gt;
    //res.setHeader('Access-Control-Allow-Origin', 'http://localhost:8080'); //no funciona?&lt;br /&gt;
    res.setHeader('Access-Control-Allow-Origin', '*'); //funciona&lt;br /&gt;
    //res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE'); // If needed&lt;br /&gt;
    //res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,contenttype'); // If needed&lt;br /&gt;
    //res.setHeader('Access-Control-Allow-Credentials', true); // If needed&lt;br /&gt;
&lt;br /&gt;
    res.setHeader(&amp;quot;Content-Type&amp;quot;, &amp;quot;text/html; charset=utf-8&amp;quot;);&lt;br /&gt;
    res.writeHeader(200);&lt;br /&gt;
    connection.query(&amp;quot;SELECT * from comunitats&amp;quot;, function(err, rows){&lt;br /&gt;
&lt;br /&gt;
      if(err != null) {&lt;br /&gt;
        res.end(&amp;quot;Query error:&amp;quot; + err);&lt;br /&gt;
      } else {&lt;br /&gt;
        for (var i = 0; i &amp;lt; rows.length; i++) {&lt;br /&gt;
          console.log(rows[i].comunitat);&lt;br /&gt;
          //res.write(rows[i].comunitat + '&amp;lt;br /&amp;gt;');&lt;br /&gt;
          res.write(&amp;quot;&amp;lt;option value=\&amp;quot;&amp;quot; + rows[i].id_com + &amp;quot;\&amp;quot;&amp;gt;&amp;quot; + rows[i].comunitat + &amp;quot;&amp;lt;/option&amp;gt;&amp;quot;);&lt;br /&gt;
        };&lt;br /&gt;
        res.end(&amp;quot;&amp;quot;);&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    });&lt;br /&gt;
&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
}).listen(8080);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Per tal de no tenir problemes amb l'origen del Request hem hagut de ficar la línia:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
res.setHeader('Access-Control-Allow-Origin', '*');&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Versions==&lt;br /&gt;
'''v1'''.&lt;br /&gt;
 &lt;br /&gt;
*NodeJS en el servidor. Des de NodeJS es fan els accessos a la base de dades de municipis. El servidor retorna al client una llista de comunitats/províncies/municipis separats amb caràcters delimitadors (això ho volem millorar en la següent versió).&lt;br /&gt;
&lt;br /&gt;
'''v2'''.&lt;br /&gt;
 &lt;br /&gt;
*Utilitzem la Fetch API per fer les crides asíncrones al servidor.&lt;br /&gt;
*En el servidor (NodeJS) construïm una cadena amb format JSON que serà el format d'intercanvi amb el client (en la versió 3 això ho millorarem).&lt;br /&gt;
&lt;br /&gt;
'''v3. Orientem el codi a POO'''&lt;br /&gt;
&lt;br /&gt;
*En el servidor (NodeJS) creem un objecte JSON de les comunitats/províncies/municipis, i ara el codi és més elegant (i menys procliu a errors de sintaxi). Però per enviar l'objecte JSON al client l'hem de convertir a cadena (''JSON.stringify'').&lt;br /&gt;
*En el client creem les selects i options amb ''createElement'' i queda un codi més elegant (però potser més complicat).&lt;br /&gt;
&lt;br /&gt;
'''v4. '''&lt;br /&gt;
&lt;br /&gt;
En les versions anteriors hem fet un '''if''' dins el servidor NodeJS per saber si estem cercant les comunitats, províncies o municipis. Aquesta part la podem fer més elegant fent que el servidor '''node_http_server.js''' sigui més petit, i redirigint el codi als scripts '''comunitats.js''', '''search_prov.js''' i '''search_mun.js''', que tindran la lògica de connectar-se a la base de dades, cercar la informació que interessa, i construir l'objecte JSON que enviarem al client. Això ho aconseguim amb el següent codi mínim:&lt;br /&gt;
&lt;br /&gt;
El servidor node http:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
var http = require('http');&lt;br /&gt;
var url = require('url');&lt;br /&gt;
&lt;br /&gt;
// Create a simple Web Server to respond to requests&lt;br /&gt;
http.createServer(function(req, res){&lt;br /&gt;
    console.log(req.url);&lt;br /&gt;
    var urlparsed = url.parse(req.url,true);&lt;br /&gt;
    console.log(urlparsed.pathname);&lt;br /&gt;
    if (urlparsed.pathname!=&amp;quot;/favicon.ico&amp;quot;){&lt;br /&gt;
        var funct = require('.'+urlparsed.pathname);&lt;br /&gt;
        funct.main(req,res);&lt;br /&gt;
    }&lt;br /&gt;
// The server will be listen on port 8080 &lt;br /&gt;
}).listen(8080);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Si cridem a ''http://localhost:8080/comunitats_prova'', aleshors la variable ''urlparsed.pathname'' valdrà ''/comunitats_prova'' (incloent la barra).&lt;br /&gt;
&lt;br /&gt;
i el script '''comunitats_prova.js''' pot incloure el següent codi:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exports.main = function(req,res){&lt;br /&gt;
  console.log(&amp;quot;COMUNITATS&amp;quot;);&lt;br /&gt;
  res.end(&amp;quot;Andalusia, Catalunya,...&amp;quot;);&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''NOTA''': tant se val cridar&lt;br /&gt;
*http://localhost:8080/comunitats_prova&lt;br /&gt;
com&lt;br /&gt;
*http://localhost:8080/comunitats_prova.js&lt;br /&gt;
&lt;br /&gt;
El ''truco'' d'aquesta manera de fer és que els mòduls es poden exportar, i això ho fem amb les línies:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
var funct = require('./comunitats');&lt;br /&gt;
funct.main(req,res);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
i dins del codi de ''comunitats.js'' trobem la línia:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exports.main = function(req,res){&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Al mètode ''main'' li podem posar el nom que vulguem, i podem tenir definits diferents mètodes.&lt;br /&gt;
&lt;br /&gt;
Més informació:&lt;br /&gt;
*https://www.sitepoint.com/understanding-module-exports-exports-node-js/&lt;br /&gt;
&lt;br /&gt;
==Feina per l'alumne==&lt;br /&gt;
Has d'adaptar l'aplicació de la pràctica anterior, que et permetia navegar per totes les comunitats, províncies i municipis, a la tecnologia Node.js en el servidor. Igual que hem vist en el codi de classe, has d'orientar el codi a JSON, a utilitzar objectes, i pots utilitzar la Fetch API en comptes de la forma més primitiva de fer les crides AJAX.&lt;br /&gt;
&lt;br /&gt;
Tens una solució al final de la pràctica, però es recomana a l'alumne encaridament (''encarecidamente'' en castellà) trobar una solució pròpia. En tot cas, i al final de tot, es pot consultar el codi proposat (que és el que s'ha vist a classe).&lt;br /&gt;
&lt;br /&gt;
==Solució==&lt;br /&gt;
Tens disponible el codi que s'ha comentat a classe, amb les tres versions:&lt;br /&gt;
*[[Fitxer:Municipis node.zip]] (actualitzat a 6 de març de 2019)&lt;br /&gt;
&lt;br /&gt;
=Entrega=&lt;br /&gt;
Els alumnes entregaran al Classroom tots els fitxers generats (fitxers html). S'empaquetaran tots aquests fitxers i es pujaran al Schoology dins del termini d'entrega de la pràctica.&lt;br /&gt;
&lt;br /&gt;
Recorda la '''normativa''' per entregar les pràctiques al Schoology: [[ASIX-M10-UF2#Normativa_d.27entrega_de_les_pr.C3.A0ctiques_al_Schoology]]&lt;br /&gt;
&lt;br /&gt;
{{Autor}}, febrer 2018&lt;br /&gt;
[[Categoria: INS Jaume Balmes]]&lt;br /&gt;
[[Categoria: Assignatura DAW-M06-WEC]]&lt;/div&gt;</summary>
		<author><name>Joan</name></author>
		
	</entry>
</feed>