I have a JSON file that looks like this. Although the file itself seems unnecessarily long for example, there is a reason why I include it. Basically, it seems to me that my file is too large to pass through TCP to my site.
{
"FormatNumber": 1,
"Team_Types": [{
"Teams": "EmmersonCod",
"Channels": [{
"Team_Name": "Tanaka",
"Team_Members": 1,
"Team_Mascot": "Dolphin"
},
{
"Team_Name": "Drago",
"Team_Members": 2,
"Team_Mascot": "Lundgren"
},
{
"Team_Name": "Apollo",
"Team_Members": 3,
"Team_Mascot": "Crews"
},
{
"Team_Name": "Cobra",
"Team_Members": 4,
"Team_Mascot": "Kai"
}
]
},
{
"Teams": "Candy",
"Channels": [{
"Team_Name": "Simson",
"Team_Members": 1,
"Team_Mascot": "The"
},
{
"Team_Name": "Rick",
"Team_Members": 2,
"Team_Mascot": "Sanchez"
}
]
},
{
"Teams": "FoxNews",
"Channels": [{
"Team_Name": "David",
"Team_Members": 1,
"Team_Mascot": "Bannon"
},
{
"Team_Name": "Rickety",
"Team_Members": 2,
"Team_Mascot": "Crickett"
},
{
"Team_Name": "Lady",
"Team_Members": 3,
"Team_Mascot": "Madam"
},
{
"Team_Name": "Random",
"Team_Members": 4,
"Team_Mascot": "Words"
},
{
"Team_Name": "Put",
"Team_Members": 5,
"Team_Mascot": "Together"
},
{
"Team_Name": "To",
"Team_Members": 6,
"Team_Mascot": "Fill"
},
{
"Team_Name": "These",
"Team_Members": 7,
"Team_Mascot": "Blanks"
},
{
"Team_Name": "And",
"Team_Members": 8,
"Team_Mascot": "Illustrate"
},
{
"Team_Name": "The",
"Team_Members": 9,
"Team_Mascot": "Issues"
},
{
"Team_Name": "We",
"Team_Members": 10,
"Team_Mascot": "Are"
},
{
"Team_Name": "Going",
"Team_Members": 11,
"Team_Mascot": "Through"
},
{
"Team_Name": "At",
"Team_Members": 12,
"Team_Mascot": "This"
},
{
"Team_Name": "Very",
"Team_Members": 13,
"Team_Mascot": "Moment"
},
{
"Team_Name": "The",
"Team_Members": 14,
"Team_Mascot": "JSON"
},
{
"Team_Name": "Is",
"Team_Members": 15,
"Team_Mascot": "Too"
},
{
"Team_Name": "Long",
"Team_Members": 16,
"Team_Mascot": "For"
},
{
"Channl_Name": "My",
"Team_Members": 17,
"Team_Mascot": "TCP"
},
{
"Team_Name": "To",
"Team_Members": 18,
"Team_Mascot": "Go"
}
]
}
]
}
The Node.js code I use for parsing is this:
var express = require('express');
var net = require("net");
var fs = require("fs");
var request = require('request');
var app = express();
var server = net.createServer();
var pack;
app.use(function(req, res, next){
res.header("Access-Control-Allow-Origin", "*");
next();
});
server.on("connection", function(socket){
pack = "";
socket.setEncoding('utf8');
socket.on("data", function(d){
pack = JSON.parse(d);
console.log(pack.Timestamp.LocalTimestamp);
app.set('dee', d);
app.get("/"+pack.FormatNumber, function(req, res){
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write(req.app.get('dee'));
res.end();
});
});
socket.once("close", function(){
console.log("connection closed");
});
});
server.on("error", function(){
console.log("connection error");
});
server.listen(9000, function(){
console.log("Server Listening to Port 9000");
});
app.listen(8081, function(){
});
This JSON file is sent as a TCP packet to my Node server, which, in turn, parses it. Code and functionality work fine in my local environment. However, when I try to push my JSON file on my Digitalocean Node.js server, I get the following error.
undefined:57
"Cha
^
SyntaxError: Unexpected token C
at Object.parse (native)
at Socket.<anonymous>
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at readableAddChunk (_stream_readable.js:146:16)
at Socket.Readable.push (_stream_readable.js:110:10)
at TCP.onread (net.js:523:20)
JSON, . , . TCP JSON.