Node.js Express Minify JSON Online Converter Full Web App Deployed to Live Website 2020

Node.js Express Minify JSON Online Converter Full Web App Deployed to Live Website 2020

 

 

Welcome folks I am back with another blog post we will be building a JSON Minifer Online Converter web app full tutorial 2020. All the source code of the application is shown below

 

Live Demo

 

You can see the live demo of the website here

 

Get Started

 

In order to make the application you need to install these node dependencies

 

npm init -y

 

npm i express ejs

 

Now make the index.ejs and copy paste the following code

 

 

<div class="container">
          <h1 class="text-center">
              Minify JSON Online
          </h1>
          <form action="/" method="post">
            <div class="form-group">
              <label for="json">JSON Code:</label>
                <textarea rows="10" cols="30" class="form-control" type="file" name="json" id="" placeholder="Paste your JSON Code here" required></textarea>
            </div>
            <div class="form-group">
                <button class="btn btn-block btn-danger">
                    Minify JSON
                </button>
            </div>
        </form>

 

 

 

Now make the index.js file and copy paste the following code

See also  Deno.js Tutorial to Capture Webpage Screenshot as PNG Image in Headless Mode Using deno-shot Library in TypeScript Full Project For Beginners

 

 

const express = require('express')
const bodyParser = require('body-parser')

const fs = require('fs')

const app = express()

app.use(bodyParser.json())
app.use(express.static('public'))
app.use(bodyParser.urlencoded({extended:false}))

const PORT = 3001

app.set('view engine','ejs')

app.get('/',(req,res) => {
    res.render('index',{title:'Minify JSON Code Online - Best JSON Online Minifer Tool - MinifyJSON.com'})
})

app.post('/',(req,res) => {
    var json = req.body.json

    var minifiedjson = JSON.stringify(JSON.parse(json));

    var outputjson = Date.now() + "output.json"

    fs.writeFileSync(outputjson,minifiedjson)

    res.download(outputjson,(err) => {
        if(err) {
            fs.unlinkSync(outputjson)
            res.send("Unable to download the file")
        }
        fs.unlinkSync(outputjson)
    })
})

app.listen(PORT,()=> {
    console.log(`App is listening on Port ${PORT}`)
})

 

 

 

Screenshot

 

 

 

 

Leave a Reply