Skip to content

Commit a8fb095

Browse files
committed
Update README.md
1 parent bc656dd commit a8fb095

File tree

1 file changed

+9
-64
lines changed

1 file changed

+9
-64
lines changed

README.md

Lines changed: 9 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,66 +1403,6 @@ Please note - before pid. This converts a pid to a group of pids for process kil
14031403

14041404
<br/>
14051405

1406-
## Q. Can you create http server in Node.js, explain the code used for it?
1407-
1408-
Yes, we can create HTTP Server in Node.js. We can use the `<http-server>` command to do so.
1409-
1410-
Following is the sample code.
1411-
1412-
```js
1413-
var http = require('http');
1414-
var requestListener = function (request, response) {
1415-
response.writeHead(200, {'Content-Type': 'text/plain'});
1416-
response.end('Welcome Viewers\n');
1417-
}
1418-
var server = http.createServer(requestListener);
1419-
server.listen(4200); // The port where you want to start with.
1420-
```
1421-
1422-
<div align="right">
1423-
<b><a href="#table-of-contents">↥ back to top</a></b>
1424-
</div>
1425-
1426-
## Q. How to load html in Node.js?
1427-
1428-
To load HTML in Node.js we have to change the “Content-type” in the HTML code from text/plain to text/html.
1429-
1430-
```js
1431-
fs.readFile(filename, "binary", function(err, file) {
1432-
if(err) {
1433-
response.writeHead(500, {"Content-Type": "text/plain"});
1434-
response.write(err + "\n");
1435-
response.end();
1436-
return;
1437-
}
1438-
1439-
response.writeHead(200);
1440-
response.write(file, "binary");
1441-
response.end();
1442-
});
1443-
```
1444-
1445-
Now we will modify this code to load an HTML page instead of plain text.
1446-
1447-
```js
1448-
fs.readFile(filename, "binary", function(err, file) {
1449-
if(err) {
1450-
response.writeHead(500, {"Content-Type": "text/html"});
1451-
response.write(err + "\n");
1452-
response.end();
1453-
return;
1454-
}
1455-
1456-
response.writeHead(200, {"Content-Type": "text/html"});
1457-
response.write(file);
1458-
response.end();
1459-
});
1460-
```
1461-
1462-
<div align="right">
1463-
<b><a href="#table-of-contents">↥ back to top</a></b>
1464-
</div>
1465-
14661406
## Q. How can you listen on port 80 with Node?
14671407

14681408
Instead of running on port 80 we can redirect port 80 to your application\'s port (>1024) using
@@ -1494,15 +1434,18 @@ jwt.sign(payload, secretOrPrivateKey, [options, callback])
14941434
* **Payload** - Contains the claims that provide information about a user who has been authenticated along with other information such as token expiration time.
14951435
* **Signature** - Final part of a token that wraps in the encoded header and payload, along with the algorithm and a secret
14961436

1497-
**Installation**
1437+
**Installation:**
14981438

14991439
```bash
15001440
npm install jsonwebtoken bcryptjs --save
15011441
```
15021442

1503-
**Example**: AuthController.js
1443+
**Example**:
15041444

15051445
```js
1446+
/**
1447+
* AuthController.js
1448+
*/
15061449
var express = require('express');
15071450
var router = express.Router();
15081451
var bodyParser = require('body-parser');
@@ -1536,10 +1479,12 @@ router.post('/register', function(req, res) {
15361479
});
15371480
```
15381481

1539-
**config.js**
1482+
**config.js:**
15401483

15411484
```js
1542-
// config.js
1485+
/**
1486+
* config.js
1487+
*/
15431488
module.exports = {
15441489
'secret': 'supersecret'
15451490
};

0 commit comments

Comments
 (0)