Last active
April 23, 2018 07:57
-
-
Save vadym-vorobel/99ca0ee6fb9c4aad0fce666769b95a8b to your computer and use it in GitHub Desktop.
Working with async functions and modules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some important data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
add: (a, b) => a + b, | |
sub: (a, b) => a - b, | |
mul: (a, b) => a * b, | |
div: (a, b) => a / b, | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const http = require('http'); | |
const { add } = require('./arithmetic'); | |
const PORT = process.env.PORT || 3000; | |
const [_, __, a = 0, b = 0] = process.argv; | |
console.log(`Adding ${a} + ${b} = ${add(a, b)}`); | |
http.createServer((req, res) => { | |
res.writeHead(200, { 'Content-Type': 'text/plain' }); | |
fs.readFile('data.txt', (error, data) => { | |
if (!error) { | |
res.end(data.toString()); | |
} else { | |
res.end('An error ocurred!', error.toString()); | |
} | |
}); | |
}).listen(PORT, () => { | |
console.log(`Listening port ${PORT}...`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment