Tag: json

获取package.json文件中另一个字段的值(npm)

我有以下package.json文件: { "main": "./dist/index.js", "scripts": { "build": "tsc", "build:live": "tsc && node ./dist/index.js" }, … } 我怎么能得到的main领域的价值,然后把它放到命令node ./dist/index.js ,这样的事情(只是一个例子,我知道这$是ENVvariables): { "main": "./dist/index.js", "scripts": { "build": "tsc", "build:live": "tsc && node $main" }, … } 提前致谢

JavaScriptlogging对象而不在\ n上执行换行符

我有一个对象: class MyObject{ constructor(prop_a, prop_b, prop_c) { this.property_a = property_a; this.property_b = property_b; this.property_c = property_c; } const myObject = new MyObject(…data); 它在日志输出中看起来像这样: myObject { property_a:0001, property_b:somestringsandlettersthat\n havenewlines\n andmorenwelines\n andmorenwelines, property_c:someotherstuff } 但我想要这样的: myObject { property_a:0001, property_b:somestringsandlettersthat havenewlines andmorenwelines, andmorenwelines property_c:someotherstuff } 新行也应该在\ n不仅在新的属性上。 我使用的logging器是: https : //github.com/VeliovGroup/Meteor-logger 在console.log(myObject)中看起来更糟糕: myObject { property_a:0001, property_b:somestringsandlettersthat\n havenewlines\n andmorenwelines\n […]

调用代码接连完成node.js

我的Node.js项目有问题。 我有一些代码,通过JSON的整个列表,并打印“1” ,也有一些代码是使用API​​和打印“2”。 现在程序打印: 2 1 我想要打印的程序: 1 2 我的代码: //include libraries const apigClientFactory = require('aws-api-gateway-client'); const tabletojson = require('tabletojson'); const Promise = require('promise'); //Global variables const url = '****'; var jsonOutput = {}; //////////////////////1///////////////////////// //Convert Html tables to Json object tabletojson.convertUrl(url, function(tablesAsJson) { var exchangeJson = tablesAsJson[0]; console.log("1"); var j = 0; for(var i […]

解决 – 如何使用内容types:应用程序/ JSON,与节点JS上的请求+ restfulapi

如何理解内容typesaplication / json的内容,如果我有restful api模块,并且在节点服务器上请求 var request = require('request'); app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json()); request({ url: 'http://localhost/4000/notes/12vdsgte5657', method: 'POST', json: {mes_id: '12vdsgte5657'} }, function(error, response, body){ console.log(body); }); 这在API路由器上 module.exports = function(app, db) { var ObjectID = require('mongodb').ObjectID; app.get('/notes/:id', (req, res) => { //const id = req.params.id; console.log(req.body,id) console.log(req.params.id,new ObjectID(id)) const details = { '_id': new […]

在node.js中检索JSON数据时出错

我试图做一个Android应用程序,显示我的AWS ec2实例上的顶部命令数据。 以下是我写的node.js文件。 它使用topparser npm模块发送最高命令结果。 并且使用checkCpuUsage函数,如果cpu使用率大于1%,它会发送一个通知。 var express = require('express'); var app = express(); var fs = require('fs'); var spawn = require('child_process').spawn; var topparser=require("topparser"); var FCM = require('fcm-node'); var server = app.listen(8080); var regTokens = []; var bodyParser = require('body-parser'); app.use(bodyParser.json()); let data_builder = ""; const DEFAUT_TOP_DURATION = 2000; function getTopData(callback, duration) { duration = […]

这个NodeJS API是否正确完成? – Chatfuel不会按照预期parsing它

Chatfuel不parsingJSON-API返回的整个jsonstring。 任何帮助是受欢迎的。 虽然从API返回的JSON看起来像这样(在邮递员): { "messages": [ { "text": "i think you should study" }, { "text": "Mikrobiologi" } ] } 信使机器人只发送第一个文本。 我的应用程序代码: router.get('/ask/:question', function(req, res){ var output = []; var keywords = req.params.question.split(' '); var answer = qHandler.search(keywords); answer.then(function(books){ output.push({text: 'i think you should study'}) for (var i = books.length; i > 0; i–){ output.push({text: […]

映射JSON数组之间的值

我似乎遇到了一个相当不寻常的问题。 使用表单生成器我能够存储和呈现一个JSON格式的pipe理员创build的表单,如下所示: 编辑 :这是我从MongoDB拉数据,因此ID,我直接推我的生成的JSON到Mongo,我取消了取回数据的ID部分。 { "_id" : ObjectId("5985608427f8510788b468ab"), "fdata" : [ { "type" : "header", "subtype" : "h1", "label" : "Date Of Commencement" }, { "type" : "paragraph", "subtype" : "p", "label" : "The partnership business shall be deemed to have commenced on and from&nbsp;<div><br></div>" }, { "type" : "date", "required" : true, "label" : […]

发送一个http请求到一个graphql api时“parsingJSON的问题”

我试图发送一个HTTP请求到Githubs graphql API(V4)。 我的猜测是我的查询格式是错误的。 下面的代码用于向api发送POST请求。 app.get('/fetch-data', function(req, res, next) { const access_token = settings.dev.TOKEN; const query = {query: { viewer: { 'login': 'muckbuck' } }}; const options = { uri: 'https://api.github.com/graphql', method: 'POST', headers: { 'Accept': 'application/json', 'Authorization': "Bearer " + access_token, 'User-Agent': 'request', 'contentType': "application/graphql", }, data: query }; function callback(error, response, body) { […]

我如何parsing大型tsv文件通过Nodejs JSON

我有一个370MB的文件。 我需要parsing,然后更新mongodb中的条目,我已经使用npm node-tsv-json.It适用于小文件,但不适合大one.It说致命错误:CALL_AND_RETRY_LAST分配失败 – JavaScript堆内存不足

Python请求:从Nodejs HTTP服务器请求突然缓慢

我有一个NodeJS HTTP服务器,显示一个JSON文件,每秒更新多次。 样本数据: { "MainText": [{ "field1": "text", "field2": "text", "field3": 1234 }, { "field1": "text", "field2": "text", "field3": 1234 }, { "field1": "text", "field2": "text", "field3": 1234 } ] } 通常在一段时间之后,这个JSON中这样的条目的数量增长到约200k或更多。 我必须将整个JSON导入一个pandas数据框,我正在使用以下方法: df = pd.DataFrame(json.loads(requests.get(url).text)) 通常这大概需要0.3秒。 但是对于我来说没有任何理由,在几个请求之后,它开始花费接近4秒(几乎)相同的固定大小的JSON。 在发出请求时,CPU或RAM的使用量没有变化。 如果我重新启动NodeJS服务器,则问题会暂时解决,但稍后会回来。 我是否需要closures与HTTP服务器的连接? 我希望180K行的文本是不是太多的请求从服务器快速获取? 我应该寻找一种将JSON数据加载到pandas数据框的更有效的方法吗?