Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Update server.js #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 37 additions & 6 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,39 @@
var http = require('http');
var express = require('express');
var app = express();

http.createServer(function (req, res) {

res.writeHead(200, { 'Content-Type': 'text/html' });
res.end('Hello, world!');
'use strict';
// node v8.11.3
const Buffer = require('buffer').Buffer;
const path = require('path');
const fs = require('fs');

/**
* @param {string} filename
*/

/**
* @param {string} base64str
* @param {string} filename
*/
function decode_base64(base64str, filename) {
let buf = Buffer.from(base64str, 'base64');

fs.writeFile(path.join(__dirname, '/public/', filename), buf, function(error) {
if (error) {
throw error;
} else {
console.log('File created from base64 string!');
return true;
}
});
}


app.get('/:img',function(req,res,next) {
var img2 =req.params.img;

}).listen(process.env.PORT || 8080);
var newimg=img2.replace(/-/g,'/');
res.send(newimg);
decode_base64(newimg,'img.jpg');
});
app.listen(process.env.PORT || 1337);