node js and microservices code example
Example 1: writefile in node js
// write_stream.js
const fs = require('fs');
let writeStream = fs.createWriteStream('secret.txt');
// write some data with a base64 encoding
writeStream.write('aef35ghhjdk74hja83ksnfjk888sfsf', 'base64');
// the finish event is emitted when all data has been flushed from the stream
writeStream.on('finish', () => {
console.log('wrote all data to file');
});
// close the stream
writeStream.end();
Example 2: writefile in node js
fs.writeFile('2pac.txt', 'Some other lyric', 'ascii', callback);
Example 3: microservices architecture node
var express = require('express')
var app = express();
var port = process.env.PORT || 3000;
var routes = require('./api/routes');
routes(app);
app.listen(port,function(){
console.log('Server started on port: ' + port);
});