I am trying to print autocompletion of a js file using nodejs and tern.
Ternjs has the worst documentation i have ever seen.
var tern = require("tern")
var ternServer = new tern.Server({})
var requestDetails = {
"query": {
"type": "completions",
"file": "myfile.js",
"end": {"line":0,"ch":3},
"types":true,
"includeKeywords":true,
"sort":true,
"guess":true,
"docs":true,
"urls":true,
"origins":true,
"lineCharPositions":true,
"caseInsensitive":true
},
"files": [
{
"type": "full",
"name": "myfile.js",
"text": 'req'
}
]
}
ternServer.request(requestDetails, function(error, success){
console.log(success);
});
Its not working though if I use con it provided continue and const. But not after that. While in atom plugin it provided require module autocomplete. Am i missing something.
Also this is the .tern-project file
{
"ecmaVersion": 6,
"libs": [
"browser",
"jquery",
"requirejs",
"commonjs"
],
"plugins": {
"complete_strings": {
"maxLength": 15
},
"node": {},
"lint": {},
"doc_comment": {
"fullDocs": true,
"strong": true
}
}
}
The autocomplete libraries are not loaded when you start the server in this way. Simply defining them in the .tern_project file doesn't seem to work.
If you start the server using node_modules/tern/bin/tern, you'll get a port then you can successfully POST a request and get the completions that way.
curl -H "Content-Type:e": "completions","file": "myfile.js","end": {"line":0,"ch":3},"types":true,"includeKeywords":true,"sort":true,"guess":true,"docs":true,"urls":true,"origins":true,"lineCharPositions":true,"caseInsensitive":true},"files": [{"type": "full","name": "myfile.js","text": "req"}]}' http://localhost:[PORT]
If that doesn't work for you, you can manually add the def files like so.
var tern = require("tern");
var fs = require("fs");
var ternServer = new tern.Server({ "async": true, "defs": findDefs()})
var requestDetails = {
"query": {
"type": "completions",
"file": "myfile.js",
"end": { "line": 0, "ch": 3 },
"types": true,
"includeKeywords": true,
"sort": true,
"guess": true,
"docs": true,
"urls": true,
"origins": true,
"lineCharPositions": true,
"caseInsensitive": true,
},
"files": [{
"type": "full",
"name": "myfile.js",
"text": 'req'
}]
}
ternServer.request(requestDetails, function(error, success) {
console.log(success);
});
function findDefs() {
var defs = [];
defs.push(JSON.parse(fs.readFileSync("node_modules/tern/defs/ecmascript.json", "utf8")));
defs.push(JSON.parse(fs.readFileSync("node_modules/tern/defs/browser.json", "utf8")));
defs.push(JSON.parse(fs.readFileSync("node_modules/tern/defs/jquery.json", "utf8")));
defs.push(JSON.parse(fs.readFileSync("node_modules/tern/defs/underscore.json", "utf8")));
return defs;
}
If you start the server using node_modules/tern/bin/tern, it will show a port then you can successfully POST a request and get the result.
curl -H "Content-Type:e": "completions","file": "myfile.js","end": {"line":0,"ch":3},"types":true,"includeKeywords":true,"sort":true,"guess":true,"docs":true,"urls":true,"origins":true,"lineCharPositions":true,"caseInsensitive":true},"files": [{"type": "full","name": "myfile.js","text": "req"}]}' http://localhost:[PORT]
Related
I need to build a treeview from an XML file. I don't want to use AJAX, as I can simply read the file from my disk (I'm building this app on Electron)
fs.readFile('./xmlfile.xml', function(err, data) {};
Is there anyone that could guide me how to build a tree of an custom made XML file? Basically I'd like to be able to build a tree from any XML data I put into my file.
I've already tried using JStree, but I keep having the same issue with it - it doesn't spit any errors in the console and prints a blank page.
testData is where keep my xmlfile.xml (file is definetely valid and it prints correctly when I put it through console log)
$(document).ready(function() {
// NeDB - Database init
var Datastore = require('nedb');
var fs = require('fs');
fs.readFile('./xmlfile.xml', function(err, testData) {
$('#cRIO_tree')
.jstree({
"core": {
"animation": 0,
"check_callback": true,
"icon": "../assets/tree.png",
"themes": {
"stripes": true
},
"xml_data": {
"data": testData,
"progressive_render": "true"
},
},
"dnd": {
"always_copy": true
},
"types": {
"#": {
"max_children": 1,
"max_depth": 10,
"valid_children": ["root"]
},
"root": {
"valid_children": ["default"]
},
"default": {
"icon": "glyphicon glyphicon-tree-deciduous",
"valid_children": ["default", "file"]
},
"file": {
"icon": "glyphicon glyphicon-flash",
"valid_children": []
}
},
"plugins": ["contextmenu", "dnd", "search", "state", "types",
"sort", "wholerow", "themes", "xml_data"]
})
}
}
Problem is that no matter what I put into my xml - it simply doesn't print it. I even tried examples from
https://old.jstree.com/documentation/xml_data
<!-- FLAT -->
<root>
<item id="root_1" parent_id="0" state="closed">
<content>
<name><![CDATA[Node 1]]></name>
</content>
</item>
<item id="node_2" parent_id="root_1">
<content>
<name><![CDATA[Node 2]]></name>
</content>
</item>
</root>
and that doesn't seem to be working..
Every time I open a React Native app with Expo, I get this massive message in the console with meta data about the app, that doesn't actually do much to help me debug. Especially because it's the same info every time, and it shows up every time the app reloads (even with hot or live reloading):
Running application "main"
with appParams: {
"rootTag": 171,
"initialProps": {
"exp": {
"manifest": {
"splash": {
"backgroundColor": "#1c2d3c"
},
"packagerOpts": {
"lanType": "ip",
"urlRandomness": "e4-nfi",
"hostType": "tunnel",
"dev": true,
"minify": false
},
"debuggerHost": "localhost:19001",
"bundleUrl": "http://localhost:19001/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false&assetPlugin=pathToProjectFiles",
"facebookAppId": "FBAppIdGoesHere",
"android": {
"splash": {
"xxhdpi": "./src/assets/img/splash-android.png",
"backgroundColor": "#1c2d3c",
"xxxhdpiUrl": "http://localhost:19001/assets/./src/assets/img/splash-android.png",
"xhdpi": "./src/assets/img/splash-android.png",
"hdpi": "./src/assets/img/splash-android.png",
"xxxhdpi": "./src/assets/img/splash-android.png",
"resizeMode": "cover",
"ldpi": "./src/assets/img/splash-android.png",
"xxhdpiUrl": "http://localhost:19001/assets/./src/assets/img/splash-android.png",
"ldpiUrl": "http://localhost:19001/assets/./src/assets/img/splash-android.png",
"xhdpiUrl": "http://localhost:19001/assets/./src/assets/img/splash-android.png",
"hdpiUrl": "http://localhost:19001/assets/./src/assets/img/splash-android.png",
"mdpi": "./src/assets/img/splash-android.png",
"mdpiUrl": "http://localhost:19001/assets/./src/assets/img/splash-android.png"
},
"config": {
"googleSignIn": {
"apiKey": "APIKeyGoesHere",
"certificateHash": "HashGoesHere"
}
},
"iconUrl": "http://localhost:19001/assets/./src/assets/img/icon-android.png",
"package": "com.organizationName.apps",
"permissions": ["CAMERA", "INTERNET", "LOCATION", "READ_EXTERNAL_STORAGE", "READ_INTERNAL_STORAGE", "WRITE_EXTERNAL_STORAGE", "com.anddoes.launcher.permission.UPDATE_COUNT", "com.android.launcher.permission.INSTALL_SHORTCUT", "com.google.android.c2dm.permission.RECEIVE", "com.google.android.gms.permission.ACTIVITY_RECOGNITION", "com.google.android.providers.gsf.permission.READ_GSERVICES", "com.htc.launcher.permission.READ_SETTINGS", "com.htc.launcher.permission.UPDATE_SHORTCUT", "com.majeur.launcher.permission.UPDATE_BADGE", "com.sec.android.provider.badge.permission.READ", "com.sec.android.provider.badge.permission.WRITE", "com.sonyericsson.home.permission.BROADCAST_BADGE"],
"icon": "./src/assets/img/icon-android.png",
"versionCode": 10
},
"slug": "app-name-goes-here",
"facebookDisplayName": "NameOfApp",
"icon": "./src/assets/img/icon-android.png",
"primaryColor": "#cccccc",
"isVerified": true,
"version": "1.1.5",
"xde": true,
"name": "NameOfApp",
"facebookScheme": "SomeFBSchemeCodeGoesHere",
"iconUrl": "http://localhost:19001/assets/./src/assets/img/icon-android.png",
"id": "#jhwheeler/name-of-app",
"hostUri": "localhost:19000",
"orientation": "portrait",
"sdkVersion": "27.0.0",
"env": {},
"hooks": {
"postPublish": [{
"config": {
"organization": "organizationNameHere",
"project": "projectNameHere",
"authToken": "authTokenGoesHere"
},
"file": "sentry-expo/upload-sourcemaps"
}]
},
"loadedFromCache": false,
"ios": {
"splash": {
"resizeMode": "cover",
"imageUrl": "http://localhost:19001/assets/./src/assets/img/splash-ios.png",
"backgroundColor": "#1c2d3c",
"image": "./src/assets/img/splash-ios.png"
},
"supportsTablet": false,
"iconUrl": "http://localhost:19001/assets/./src/assets/img/icon-ios.png",
"infoPlist": {
"NSLocationAlwaysUsageDescription": "Nice message goes here",
"NSLocationWhenInUseUsageDescription": "Nice message goes here"
},
"bundleIdentifier": "com.orgName.apps",
"buildNumber": "1",
"icon": "./src/assets/img/icon-ios.png"
},
"logUrl": "http://localhost:19000/logs",
"privacy": "unlisted",
"mainModuleName": "node_modules/expo/AppEntry",
"developer": {
"projectRoot": "/path/to/project",
"tool": "xde"
},
"description": "descriptionOfApp"
},
"appOwnership": "expo",
"initialUri": "exp://localhost:19000",
"shell": 0
}
}
}.__DEV__ === true, development - level warning are ON, performance optimizations are OFF
If I'm looking at the Expo console, it is prefaced with BugReporting extraData: and wraps the above in a JS object. I don't know if this is unique to Expo or a React Native message, but either way:
Is there any way to get rid of this message? It's so large that it makes finding actual errors much more laborious.
I solved a similar problem by adding to the project root:
const ignoreConsoleMessages = [
'Running "main" with'
]
const origLog = console.log
console.log = (...params) => (
typeof params[0] === 'string' &&
ignoreConsoleMessages.reduce((acc, i) => acc + ~params[0].indexOf(i), 0)
? null
: origLog(...params)
)
I'm not familiar with Expo, but I encountered this log message recently with a vanilla RN project. I was able to remove it by adding the following to my index file:
console.ignoredYellowBox = ['react-native BugReporting extraData:'];
I am trying to get output of log4js in JSON format so I can easily trace it.
Is there any way that we have to set in configuration.json so output produced by log4js will be in JSON format?
Currently I am using following config.
{
"appenders": [
{
"category": "XXXXX",
"type": "dateFile",
"filename": "XXXXXXXX",
"pattern": "-from-MM-dd",
"layout": {
"type": "messagePassThrough"
}
},
{
"category": "XXXXXXXXX",
"type": "dateFile",
"filename": "XXXXXXXX",
"pattern": "-from-MM-dd",
"layout": {
"type": "messagePassThrough"
}
}
],
"levels": {
"XXXXConfig": "INFO",
"XXXXXjectConfig" : "INFO"
}
}
and I got output is in following format :
DEBUG: 1458562784032 : 2016-03-21T12:19:44.4444+00:00 : Data in request: : {
"action": "XXXXXXX",
"user": {
"username": "XXXX",
"id" : XXXX,
"pos" : XXXX
},
"version": 111
}
instead I want it in (Something like following structure) :
{"id" : "1458562784032", "time" : "2016-03-21T12:19:44.4444+00:00", "message" : "Data in request:", "data" : "{
"action": "XXXXXXX",
"user": {
"username": "XXXX",
"id" : XXXX,
"pos: : XXXX
},
"version": 111
}" }
May be there is something I missing in config.
Thanks for helping.
There are two ways to implement this issue now, you can add your own layouts or pattern format.
Below is the sample code of adding your own layouts with JSON format
const log4js = require('log4js');
log4js.addLayout('json', function(config) {
return function(logEvent) { return JSON.stringify(logEvent) + config.separator; }
});
log4js.configure({
appenders: {
out: { type: 'stdout', layout: { type: 'json', separator: ',' } }
},
categories: {
default: { appenders: ['out'], level: 'info' }
}
});
const logger = log4js.getLogger('json-test');
logger.info('this is just a test');
We can use bunyan for same purpose which logs your console log in JSON format.
Here is the npm link for node : https://www.npmjs.com/package/bunyan.
Also even if you want to use log4js then create your own pattern and write log file into JSON format.
Thanks.
I am trying to create an MS SQL db with breeze-breeze sequelize and i like to generate the ids on the db server. My solution is oriented on the tempHire example from the breeze samples repo
My Metadata.json looks like this:
{
"metadataVersion": "1.0.5",
"namingConvetion": "camelCase",
"localQueryComparisonOptions": "caseInsensitiveSQL",
"dataServices": [{
"serviceName": "breeze/",
"hasServerMetadata": true,
"useJsonp": false
}],
"structuralTypes": [{
"shortName": "User",
"namespace": "Model",
"autoGeneratedKeyType": "Identity",
"defaultResourceName": "Users",
"dataProperties": [{
"nameOnServer": "id",
"dataType": "Int32",
"isPartOfKey": true,
"isNullable": false
}, {
"name": "firstName",
"dataType": "String"
}, {
"name": "lastName",
"dataType": "String"
}, {
"name": "userName",
"dataType": "String",
"isNullable": false,
"maxLength": 64,
"validators": [{
"name": "required"
}, {
"maxLength": 64,
"name": "maxLength"
}]
}, {
"name": "email",
"dataType": "String"
}]
}],
"resourceEntityTypeMap": {
"Users": "User:#Model"
}
}
though this will not create an identity id column.
the created table looks like the following create script:
CREATE TABLE [User] (
[id] INTEGER NOT NULL ,
[firstName] NVARCHAR(255) DEFAULT NULL,
[lastName] NVARCHAR(255) DEFAULT NULL,
[userName] NVARCHAR(64) NOT NULL DEFAULT '',
[email] NVARCHAR(255) DEFAULT NULL,
PRIMARY KEY ([id])
)
In addition here are some breeze server side implementations:
var dbConfig = {
user: 'user',
password: 'secret',
dbName: 'dbname'
};
var sequelizeOptions = {
host: 'hostname',
dialect: 'mssql',
port: 1433
};
function createSequelizeManager() {
var metadata = readMetadata();
var sm = new SequelizeManager(dbConfig, sequelizeOptions);
sm.importMetadata(metadata);
return sm;
}
var _sequelizeManager = createSequelizeManager();
_sequelizeManager.authenticate();
_sequelizeManager.sync(false /* createDb */)
.then(seed)
.then(function () {
console.log('db init successful');
});
Do i have a wrong configuration? Is the Identity not available with the mssql dialect? Am i doing something wrong?
With the configuration is nothing wrong i guess.
I just found out that there is a bug in the MetadataMapper from breeze-sequelize. I tested it with the sequelize version 2.1.3 and 3.x.
The autoIncrement attribute for sequelize will never get set. The if statement will never be true. I'll report this on github. ;)
The fix would be the following code in the MetadataMapper.js at line 134:
if (attributes.type.key == "INTEGER" || attributes.type.key =="BIGINT") {
attributes.autoIncrement = true;
}
In the original code the if statement is attributes.type== "INTEGER" || attributes.type=="BIGINT" where the type actually never is a string.
I'm using node-log4js.
(it's log4JS, not log4J!)
I thought of the loggers 'categories' to be just like the Strings you put in Log4J into the constructor of a logger (normally you put your fqn class name there), so that log4j can put logged things to the right location.
I got the following config:
{
"appenders": [
{
"type": "console",
},
{
"type": "file",
"absolute": true,
"filename": "/tmp/app.log",
"maxLogSize": 20480,
"backups": 10
},
{
"type": "console",
"category": "app.access"
}
]
}
The desired behaviour would be that all "app.access" stuff only goes to the last appender (which is, at the moment, the console, too, but could change in future). At the moment, all loggings with the category 'app.access' will be logged twice to console and once to file.
Is there a way to give those other two appenders a "all but app.access"-category? How?
Thank you very much in advance
I had a similar requirement. I wanted to exclude a bunch of categories from the console logger.
I wrote something based on the logLevelFilter, which I called categoryFilter.
categoryFilter.js:
"use strict";
var log4js = require('log4js');
function categoryFilter (excludeCategories, appender) {
return function(logEvent) {
if (excludeCategories.every(function(x){return (x!=logEvent.category);})) {
appender(logEvent);
}
};
}
function configure(config) {
log4js.loadAppender(config.appender.type);
var appender = log4js.appenderMakers[config.appender.type](config.appender);
return categoryFilter(config.exclude, appender);
}
exports.appender = categoryFilter;
exports.configure = configure;
To use it, I have this snippet near the beginning of my app:
var log4js = require('log4js');
log4js.loadAppender('categoryFilter',require('./src/categoryFilter'));
log4js.configure('log4js-conf.js');
My configuration file has the following:
{
"appenders": [
{
"type": "file",
"filename": "logs/logfile.log",
"maxLogSize": 20480,
"backups": 3
},
{
"type": "categoryFilter",
"exclude":["results"],
"appender":{
"type": "console"
}
},
],
"replaceConsole":true
}
I'd be interested in your thoughts.
I faced a similar problem and here's how I resolved it - using the levels.
Used the following config file:
{
"appenders": [
{
"type": "logLevelFilter",
"level": "INFO",
"appender": {
"type": "console",
"layout": {
"type": "colored",
"pattern": "[%d] %-5p <%c> %m"
}
}
},
{
"type": "console",
"layout": {
"type": "messagePassThrough"
},
"category": "raw"
}
]
}
The use 2 different log4js instances as follows:
var path = require('path');
var log4js = require('log4js');
log4js.configure('log4js.json');
var log = log4js.getLogger(path.basename(__filename));
var raw = log4js.getLogger('raw');
In your code use log.info(), log.warn(), log.error() or log.fatal() to have standard logs such as:
[2015-01-12 19:37:19.931] [INFO] app.js - app started
[2015-01-12 19:38:52.484] [ERROR] other.js - Error. failed to open file
Same logs above would look like this using raw.trace():
app started
Error. failed to open file
I'm using it to highlight different situations in the console. It is important to me to have it look totally different so I will notice these events. But when it is logged to a file, I don't mind if it has the timestamp (since it actually helps when looking back in time). Therefore I also have the following appender in the log4js.json file:
{
"type": "file",
"filename": "app.log",
"maxLogSize": 1048576,
"backups": 10,
"layout": {
"type": "pattern",
"pattern": "[%d] %-5p <%c> %m"
}
}
Hope this help! :)
Just assign top two appenders to a different category than "app.access" and use that category in getLogger.