-
Notifications
You must be signed in to change notification settings - Fork 96
/
11 - Express.js
40 lines (31 loc) · 1.04 KB
/
11 - Express.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
Express
- Node.js is very low-level (generally, you would need a framework to build a web app)
- Express is a web development framework for Node.js
*/
/*
Install express by running:
'npm install --save express'
Note: By using the '--save' flag, apart from installing the module, it adds the required information
to the dependencies file(package.json)
*/
// In order to start the web application, we need to load the library
var express = require('express');
// Create an instance of express
var app = express();
// Define end-points in the following way
// '/' is the root route
app.get('/', function (request, response) {
//Read a file from the file system and send it back to the response
response.sendFile(__dirname + "/README.md");
});
// Receive requests at port 8080
app.listen(8080);
/*
Run the following cmd to start node and create the end-point:
node '11 - Express.js'
Run the following cmd to make an HTTP to your local server:
curl http://localhost:8080
Expected response:
- HTTP response with README.md file
*/