Skip to content

Commit 4f50c38

Browse files
committed
CODE 6 - Web Server Express
1 parent 4617142 commit 4f50c38

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

index.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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');
45
var mongoose= require("mongoose");
56
mongoose.connect("mongodb://localhost:27017/curs_nodejs",(err, res) =>{
67
if(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();
1618
const 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
2426
server.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+
})

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
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",

0 commit comments

Comments
 (0)