File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11"use strict" //Per obtenir compatibilitat amb les ultimes versions
22
3- const http = require ( 'http' ) ;
3+ const express = require ( "express" ) ;
4+ //const http = require('http');
45var mongoose = require ( "mongoose" ) ;
56mongoose . connect ( "mongodb://localhost:27017/curs_nodejs" , ( err , res ) => {
67if ( err ) {
@@ -12,15 +13,24 @@ console.log("La base de dades está funcionant correctamente");
1213
1314//console.log("Hola mòn");
1415
15- const hostname = '127.0.0.1' ;
16+ //const hostname = '127.0.0.1';
17+ const app = express ( ) ;
1618const port = 3000 ;
1719
18- const server = http . createServer ( ( req , res ) => {
20+ /* const server = http.createServer((req, res) => {
1921 res.statusCode = 200;
2022 res.setHeader('Content-Type', 'text/plain');
2123 res.end('Hola Mundo');
2224});
2325
2426server.listen(port, hostname, () => {
2527 console.log(`El servidor se está ejecutando en http://${hostname}:${port}/`);
26- } ) ;
28+ });*/
29+
30+ app . get ( "/" , ( req , res ) => {
31+ res . send ( "Hola mòn" ) ;
32+ } )
33+
34+ app . listen ( port , ( ) => {
35+ console . log ( "Exemple d'app escoltant" ) ;
36+ } )
Original file line number Diff line number Diff line change 55 "main" : " index.js" ,
66 "scripts" : {
77 "test" : " echo \" Error: no test specified\" && exit 1" ,
8- "start" : " node index"
8+ "start" : " nodemon index"
99 },
1010 "author" : " " ,
1111 "license" : " ISC" ,
You can’t perform that action at this time.
0 commit comments