31/1/22 11:45 NodeJS - Express: DESARROLLO DE APLICACIONES WEB Y MÓVILES
NodeJS - Express
Node.js® es un entorno de ejecución para JavaScript construido con el motor de
JavaScript V8 de Chrome (https://v8.dev/) . Mientras que Express permite crear una
infraestructura web rápida, minimalista y flexible para Node.js
Recursos
Descargue y descomprima el siguiente recurso: servidorexpress1.rar
(https://aulavirtual.espol.edu.ec/courses/3423/files/1410071/download?wrap=1)
Servidor sencillo 1: desde archivos
Desde la línea de comandos en la ruta de servidorexpress1:
Instale las dependencias necesarias, con: npm install express
Ejecute: node servidorexpress1.js
En el navegador, identifique las rutas disponibles a las que responde el servidor.
Servidor sencillo 2: esqueleto de proyecto web
Para este otro ejemplo, utilizaremos el generador de aplicaciones de express
(https://expressjs.com/en/starter/generator.html) . Desde la línea de comandos, en OTRO
DIRECTORIO:
Instale las dependencias necesarias, con: npm i -g express-generator
Crea un sitio de prueba, con: express --view=ejs misitio
https://aulavirtual.espol.edu.ec/courses/3423/pages/nodejs-express?module_item_id=135964 1/4
31/1/22 11:45 NodeJS - Express: DESARROLLO DE APLICACIONES WEB Y MÓVILES
Comprueba el funcionamiento del servidor, con:
cd misitio
npm install
SET DEBUG=misitio:* & npm start
Accede a los rutas por defecto del sitio.
Reto
Crea las rutas y las páginas de respuestas para:
"/servicios"
"/servicios/locales"
"/contactenos"
Despliegue en producción
Descarga y descomprime los recursos (.gitignore y Procfile) en la carpeta de tu
proyecto: extrasHerokuApp.rar
(https://aulavirtual.espol.edu.ec/courses/3423/files/1410069/download?wrap=1) . Luego:
Desde la línea de comandos, identifica la versión de node, con: node -v
https://aulavirtual.espol.edu.ec/courses/3423/pages/nodejs-express?module_item_id=135964 2/4
31/1/22 11:45 NodeJS - Express: DESARROLLO DE APLICACIONES WEB Y MÓVILES
En package.json, agrega la clave engines, con el valor:
"engines": {
"node": "X.Y.Z"
},
Versionamiento
Desde la línea de comandos, en la carpeta del proyecto sobre NodeJS - Express.
Inicializa el versionamiento local, con: git init .
Agrega todos los archivos, con: git add .
Versiona todos los archivos, con: git commit -m "heroku version"
Express - Heroku
Heroku permite manejar las aplicaciones desde la línea de comando o desde la interfaz
web.
Obtén una cuentan en heroku (https://signup.heroku.com/login) .
Descarga el heroku-cli (https://devcenter.heroku.com/articles/heroku-cli#download-
and-install) .
Desde la línea de comandos en la ruta del proyecto, accede a Heroku, con: heroku
login
Se le pedirá que presione cualquier tecla para ir a su navegador web y completar el inicio
de sesión.
Cree un proyecto, con: heroku create
Liste las rutas remotas. Verifique si aparece la ruta remota con heroku, use: git
remote -v
https://aulavirtual.espol.edu.ec/courses/3423/pages/nodejs-express?module_item_id=135964 3/4
31/1/22 11:45 NodeJS - Express: DESARROLLO DE APLICACIONES WEB Y MÓVILES
Revisa el estado del versionamiento del proyecto, con: git status
De ser necesario, agrega los archivos en el proyecto local, con: git add .
Versiona los archivos en el proyecto local, con: git commit -m "heroku version"
Opcional: En caso que no aparezca la ruta remota para heroku
Agrega manualmente tu ruta con: git remote add heroku
https://git.heroku.com/belle-mandarine-00747.git
Despliega tu aplicación, con: git push heroku master
Abre la aplicación, con: heroku open
Fuentes
Express - Infraestructura de aplicaciones web Node.js. (2020). Retrieved 16 December 2020,
from https://expressjs.com/es/ (https://expressjs.com/es/)
Express application generator. (2021). Retrieved 28 July 2021, from
https://expressjs.com/en/starter/generator.html
(https://expressjs.com/en/starter/generator.html)
Introducción a Express/Node - Aprende sobre desarrollo web | MDN. (2020). Retrieved 16
December 2020, from https://developer.mozilla.org/es/docs/Learn/Server-
side/Express_Nodejs/Introduction (https://developer.mozilla.org/es/docs/Learn/Server-
side/Express_Nodejs/Introduction)
Express Tutorial Part 2: Creating a skeleton website - Learn web development | MDN.
(2020). Retrieved 16 December 2020, from https://developer.mozilla.org/en-
US/docs/Learn/Server-side/Express_Nodejs/skeleton_website
(https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs/skeleton_website)
Introducción a Express/Node - Aprende sobre desarrollo web | MDN. (2020). Retrieved 16
December 2020, from https://developer.mozilla.org/es/docs/Learn/Server-
side/Express_Nodejs/Introduction (https://developer.mozilla.org/es/docs/Learn/Server-
side/Express_Nodejs/Introduction)
https://aulavirtual.espol.edu.ec/courses/3423/pages/nodejs-express?module_item_id=135964 4/4