-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
96 lines (72 loc) · 2.12 KB
/
app.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const express = require('express');
const app = express();
const fs = require('fs');
const path = require('path');
const bodyParser = require('body-parser');
const cons = require('consolidate');
app.listen(5000,function(){
console.log('Server started on : http://localhost:5000 Port' )
});
app.get('/', function(req,res){
//res.setHeader('Access-Control-Allow-Origin', '*')
return res.render('Login/Login', {
title: "Login"
});
});
app.post('/login', (req, res) => {
return res.render('Home/Home', {
title: "Home"
});
});
app.get('/home', function (req, res) {
res.setHeader('Access-Control-Allow-Origin', '*')
return res.render('Home');
});
//Define Static folder
app.use(express.static(__dirname + '/Client'));
//Define View Engine
app.engine('html', cons.swig);
app.set('views', path.join(__dirname, '/Client/modules'));
app.set('view engine', 'html');
app.use(bodyParser.json({ limit: '50mb' }));
app.use(bodyParser.urlencoded({
extended: true,
limit: '50mb'
}));
/**
* Readable Stream
* Emits @data - Event to read the new data
* Emits @end - event to when there is no more data to read
*/
//create ReadableStram
const readableStream = fs.createReadStream('./input.txt');
// listen for data events
readableStream.on('data', (chunk) => {
console.log(`Received ${chunk.length} bytes of data`);
});
// listen for the end of the stream
readableStream.on('end', () => {
console.log('No more data');
});
// listen for errors
readableStream.on('error', (err) => {
console.error(`Error: ${err}`);
});
/**
* Writable Stream
* Emits @data - Event to read the new data
* Emits @end - event to when there is no more data to read
*/
// create a writable stream
const writableStream = fs.createWriteStream('./output.txt');
// write data to the stream
writableStream.write('Hello, world!\n');
writableStream.write('How are you today?\n');
/**
* Duplex Stream
* Reading from Input .txt Data and Write in output.txt
*/
// pipe data from the readable stream to the writable stream
readableStream.pipe(writableStream);
// end the stream
//writableStream.end();