Why does Express log the server object in the console every time? - node.js

Although I am still relatively new to Express.js, I think I have gotten fairly familiar with it, but there is one thing that I just can't figure out.
Why does Express log the server object (listed below) log itself in the console, even though I never specified a console.log method to list it?
I wouldn't mind it since it's a test project, but it clutters up the console and I would like to find a way to disable it. Is there a option in the express function maybe?
Server {
insecureHTTPParser: undefined,
_events: [Object: null prototype] {
request: [Function: app] EventEmitter {
_events: [Object: null prototype],
_eventsCount: 1,
_maxListeners: undefined,
setMaxListeners: [Function: setMaxListeners],
getMaxListeners: [Function: getMaxListeners],
emit: [Function],
addListener: [Function: addListener],
on: [Function: addListener],
prependListener: [Function: prependListener],
once: [Function: once],
prependOnceListener: [Function: prependOnceListener],
removeListener: [Function: removeListener],
off: [Function: removeListener],
removeAllListeners: [Function: removeAllListeners],
listeners: [Function: listeners],
rawListeners: [Function: rawListeners],
listenerCount: [Function: listenerCount],
eventNames: [Function: eventNames],
init: [Function: init],
defaultConfiguration: [Function: defaultConfiguration],
lazyrouter: [Function: lazyrouter],
handle: [Function: handle],
use: [Function: use],
route: [Function: route],
engine: [Function: engine],
param: [Function: param],
set: [Function: set],
path: [Function: path],
enabled: [Function: enabled],
disabled: [Function: disabled],
enable: [Function: enable],
disable: [Function: disable],
acl: [Function],
bind: [Function],
checkout: [Function],
connect: [Function],
copy: [Function],
delete: [Function],
get: [Function],
head: [Function],
link: [Function],
lock: [Function],
'm-search': [Function],
merge: [Function],
mkactivity: [Function],
mkcalendar: [Function],
mkcol: [Function],
move: [Function],
notify: [Function],
options: [Function],
patch: [Function],
post: [Function],
pri: [Function],
propfind: [Function],
proppatch: [Function],
purge: [Function],
put: [Function],
rebind: [Function],
report: [Function],
search: [Function],
source: [Function],
subscribe: [Function],
trace: [Function],
unbind: [Function],
unlink: [Function],
unlock: [Function],
unsubscribe: [Function],
all: [Function: all],
del: [Function],
render: [Function: render],
listen: [Function: listen],
request: [IncomingMessage],
response: [ServerResponse],
cache: {},
engines: {},
settings: [Object],
locals: [Object: null prototype],
mountpath: '/'
},
connection: [Function: connectionListener],
listening: [Function: bound onceWrapper] { listener: [Function] }
},
_eventsCount: 3,
_maxListeners: undefined,
_connections: 0,
_handle: TCP {
reading: false,
onconnection: [Function: onconnection],

Related

How do I deactivate the express server information log in node.js?

I'm trying to host a simple express server with node.js on replit.com, which so far works quite well. However, whenever I start the application, there is some seriously annoying console output:
Server {
insecureHTTPParser: undefined,
_events: [Object: null prototype] {
connection: [Function: connectionListener],
close: [Function: bound close],
listening: [ [Function: bound init], [Function] ],
upgrade: [Function],
request: [Function]
},
_eventsCount: 5,
_maxListeners: undefined,
_connections: 0,
_handle: TCP {
reading: false,
onconnection: [Function: onconnection],
[Symbol(owner_symbol)]: [Circular]
},
Server {
insecureHTTPParser: undefined,
_events: [Object: null prototype] {
request: [Function: app] EventEmitter {
_events: [Object: null prototype],
_eventsCount: 1,
_maxListeners: undefined,
setMaxListeners: [Function: setMaxListeners],
getMaxListeners: [Function: getMaxListeners],
emit: [Function],
addListener: [Function: addListener],
on: [Function: addListener],
prependListener: [Function: prependListener],
once: [Function: once],
prependOnceListener: [Function: prependOnceListener],
removeListener: [Function: removeListener],
off: [Function: removeListener],
removeAllListeners: [Function: removeAllListeners],
listeners: [Function: listeners],
rawListeners: [Function: rawListeners],
listenerCount: [Function: listenerCount],
eventNames: [Function: eventNames],
init: [Function: init],
defaultConfiguration: [Function: defaultConfiguration],
lazyrouter: [Function: lazyrouter],
handle: [Function: handle],
use: [Function: use],
route: [Function: route],
engine: [Function: engine],
param: [Function: param],
set: [Function: set],
path: [Function: path],
enabled: [Function: enabled],
disabled: [Function: disabled],
enable: [Function: enable],
disable: [Function: disable],
acl: [Function],
bind: [Function],
checkout: [Function],
connect: [Function],
copy: [Function],
delete: [Function],
get: [Function],
head: [Function],
link: [Function],
lock: [Function],
'm-search': [Function],
merge: [Function],
mkactivity: [Function],
mkcalendar: [Function],
mkcol: [Function],
move: [Function],
notify: [Function],
options: [Function],
patch: [Function],
post: [Function],
pri: [Function],
propfind: [Function],
proppatch: [Function],
purge: [Function],
put: [Function],
rebind: [Function],
report: [Function],
search: [Function],
source: [Function],
subscribe: [Function],
trace: [Function],
unbind: [Function],
unlink: [Function],
unlock: [Function],
unsubscribe: [Function],
all: [Function: all],
del: [Function],
render: [Function: render],
listen: [Function: listen],
request: [IncomingMessage],
response: [ServerResponse],
cache: {},
engines: {},
settings: [Object],
locals: [Object: null prototype],
mountpath: '/',
_router: [Function]
},
connection: [Function: connectionListener],
listening: [Function: bound onceWrapper] { listener: [Function] }
},
_eventsCount: 3,
_maxListeners: undefined,
_connections: 0,
_handle: TCP {
reading: false,
onconnection: [Function: onconnection],
[Symbol(owner_symbol)]: [Circular]
},
_usingWorkers: false,
Server {
insecureHTTPParser: undefined,
_events: [Object: null prototype] {
request: [Function: app] EventEmitter {
_events: [Object: null prototype],
_eventsCount: 1,
_maxListeners: undefined,
setMaxListeners: [Function: setMaxListeners],
getMaxListeners: [Function: getMaxListeners],
emit: [Function],
addListener: [Function: addListener],
on: [Function: addListener],
prependListener: [Function: prependListener],
once: [Function: once],
prependOnceListener: [Function: prependOnceListener],
removeListener: [Function: removeListener],
off: [Function: removeListener],
removeAllListeners: [Function: removeAllListeners],
listeners: [Function: listeners],
rawListeners: [Function: rawListeners],
listenerCount: [Function: listenerCount],
eventNames: [Function: eventNames],
init: [Function: init],
defaultConfiguration: [Function: defaultConfiguration],
lazyrouter: [Function: lazyrouter],
handle: [Function: handle],
use: [Function: use],
route: [Function: route],
engine: [Function: engine],
param: [Function: param],
set: [Function: set],
path: [Function: path],
enabled: [Function: enabled],
disabled: [Function: disabled],
enable: [Function: enable],
disable: [Function: disable],
acl: [Function],
bind: [Function],
checkout: [Function],
connect: [Function],
copy: [Function],
delete: [Function],
get: [Function],
head: [Function],
link: [Function],
lock: [Function],
'm-search': [Function],
merge: [Function],
mkactivity: [Function],
mkcalendar: [Function],
mkcol: [Function],
move: [Function],
notify: [Function],
options: [Function],
patch: [Function],
post: [Function],
pri: [Function],
propfind: [Function],
proppatch: [Function],
purge: [Function],
put: [Function],
rebind: [Function],
report: [Function],
search: [Function],
source: [Function],
subscribe: [Function],
trace: [Function],
unbind: [Function],
unlink: [Function],
unlock: [Function],
unsubscribe: [Function],
all: [Function: all],
del: [Function],
render: [Function: render],
listen: [Function: listen],
request: [IncomingMessage],
response: [ServerResponse],
cache: {},
engines: {},
settings: [Object],
locals: [Object: null prototype],
mountpath: '/',
_router: [Function]
},
connection: [Function: connectionListener],
listening: [Function: bound onceWrapper] { listener: [Function] }
},
_eventsCount: 3,
_maxListeners: undefined,
_connections: 0,
_handle: TCP {
reading: false,
onconnection: [Function: onconnection],
[Symbol(owner_symbol)]: [Circular]
},
_usingWorkers: false,
Server {
insecureHTTPParser: undefined,
_events: [Object: null prototype] {
connection: [Function: connectionListener],
close: [Function: bound close],
listening: [ [Function: bound init], [Function] ],
upgrade: [Function],
request: [Function]
},
_eventsCount: 5,
_maxListeners: undefined,
_connections: 0,
_handle: TCP {
reading: false,
onconnection: [Function: onconnection],
[Symbol(owner_symbol)]: [Circular]
},
_usingWorkers: false,
_workers: [],
_unref: false,
allowHalfOpen: true,
pauseOnConnect: false,
httpAllowHalfOpen: false,
timeout: 120000,
keepAliveTimeout: 5000,
maxHeadersCount: null,
headersTimeout: 60000,
_connectionKey: '6::::800',
[Symbol(IncomingMessage)]: [Function: IncomingMessage],
[Symbol(ServerResponse)]: [Function: ServerResponse],
[Symbol(kCapture)]: false,
[Symbol(asyncId)]: 4
}
here is my code:
const fs = require("fs");
const express = require('express');
const app = express();
const server = require('http').createServer(app);
app.get('/', (req, res) => {
res.setHeader('Content-type','text/html');
res.write(fs.readFileSync(__dirname + '/index.html'));
res.end();
});
app.get("/pages/:page", (req, res) => {
let page = req.params.page;
res.setHeader('Content-type','text/html');
res.write(fs.readFileSync(`${__dirname}/pages/${page}.html`));
res.end();
})
server.listen(800, () => {
console.log('listening on *:800');
});
How do I deactivate this? I don't want to disable console.log() itself. I believe i had the same issue a while ago, but can't remember the fix - if it wasn't just something i fixed by accident. I tried removing different portions of my code without luck and i also cannot find any similar issues online.
This is caused by replit.com echoing command results to the console.
A simple workaround is like so:
const fs = require("fs");
const express = require('express');
const app = express();
const server = require('http').createServer(app);
let {} = app.get('/', (req, res) => {
res.setHeader('Content-type','text/html');
res.write(fs.readFileSync(__dirname + '/index.html'));
res.end();
});
let {} = app.get("/pages/:page", (req, res) => {
let page = req.params.page;
res.setHeader('Content-type','text/html');
res.write(fs.readFileSync(`${__dirname}/pages/${page}.html`));
res.end();
})
let {} = server.listen(80, () => {
console.log('listening on *:80');
});
It's the app.get and server.listen calls that are returning a server object (this then gets logged).
There should be some configuration in replit.com to find this setting and change it (e.g. don't echo command results to the console), I haven't found it yet, but it's probably a better fix.

find and findone giving me model contents instead of records

I am trying to fetch one record from Mongo using the following code.
I have created a schema in another file
const mongoose = require('mongoose');
const appData = require('../../../core/utilities/appData.js');
const Schema = mongoose.Schema;
const clientListingSchema = new Schema({
...});
const clientListingsModel = mongoose.model('clientlistings', clientListingSchema);
module.exports = clientListingsModel;
And have imported the above in another file
const clientListingModel = require('./../models/clientListing');
clientListingModel.findOne({'_id': client_listings_id}).then((client_listing) => {
console.log(client_listing);
});
But I am getting something like this
model {
'$__': InternalCache {
strictMode: true,
selected: {},
shardval: undefined,
saveError: undefined,
validationError: undefined,
adhocPaths: undefined,
removing: undefined,
inserting: undefined,
version: undefined,
getters: {},
_id: 5dd4de69c7d3b8585464dadd,
populate: undefined,
populated: undefined,
wasPopulated: false,
scope: undefined,
activePaths: StateMachine {
paths: [Object],
states: [Object],
stateNames: [Array]
},
pathsToScopes: {},
ownerDocument: undefined,
fullPath: undefined,
emitter: EventEmitter {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: 0
},
'$options': true
},
isNew: false,
errors: undefined,
_doc: {
number: 3,
hub_coordinates: [
0,
0,
toBSON: [Function: toBSON],
_atomics: {},
_parent: [Circular],
_cast: [Function: _cast],
_markModified: [Function: _markModified],
_registerAtomic: [Function: _registerAtomic],
'$__getAtomics': [Function: $__getAtomics],
hasAtomics: [Function: hasAtomics],
_mapCast: [Function: _mapCast],
push: [Function: push],
nonAtomicPush: [Function: nonAtomicPush],
'$pop': [Function: $pop],
pop: [Function: pop],
'$shift': [Function: $shift],
shift: [Function: shift],
pull: [Function: pull],
splice: [Function: splice],
unshift: [Function: unshift],
sort: [Function: sort],
addToSet: [Function: addToSet],
set: [Function: set],
toObject: [Function: toObject],
inspect: [Function: inspect],
indexOf: [Function: indexOf],
remove: [Function: pull],
_path: 'hub_coordinates',
isMongooseArray: true,
validators: [],
_schema: [SchemaArray]
],
...
},
'$init': true
}
Need help figuring out how I can get only the record and not model contents.
Any help figuring this out is appreciated.
You can use lean
By default, Mongoose queries return an instance of the Mongoose Document class. Documents are much heavier than vanilla JavaScript objects, because they have a lot of internal state for change tracking.
Enabling the lean option tells Mongoose to skip instantiating a full Mongoose document and just give you the POJO.
change your code as below
clientListingModel.findOne({'_id': client_listings_id}).lean().then((client_listing) => {}
Hope it will help you.
Try for the following:
JSON.parse(JSON.stringify(client_listing))

Adding functions to a loaded node.js module

about 2 years ago, I wrote a node.js module that loads an existing module (jsts) and adds some functions to it. Here is a minimal example:
global.jsts = require("jsts");
global.jsts.algorithm.test = function() {console.log("hi")}
global.jsts.algorithm.test();
I ran it in node (v0.10.18) and it printed
hi
Now, I run the same code in nodejs (v4.2.6) and it prints:
TypeError: global.jsts.algorithm.test is not a function
Is there a way to make it work with the current version of nodejs?
EDIT: I also did:
global.jsts.algorithm.x = 1
console.log(global.jsts.algorithm)
and here is the output:
{ Centroid:
{ [Function: ge]
area2: [Function],
centroid3: [Function],
getCentroid: [Function] },
CGAlgorithms:
{ [Function: he]
orientationIndex: [Function],
signedArea: [Function],
distanceLineLine: [Function],
isPointInRing: [Function],
computeLength: [Function],
isCCW: [Function],
locatePointInRing: [Function],
distancePointLinePerpendicular: [Function],
computeOrientation: [Function],
distancePointLine: [Function],
isOnLine: [Function],
CLOCKWISE: -1,
RIGHT: -1,
COUNTERCLOCKWISE: 1,
LEFT: 1,
COLLINEAR: 0,
STRAIGHT: 0 },
ConvexHull:
{ [Function: me]
extractCoordinates: [Function],
RadialComparator: { [Function: ye] polarCompare: [Function] } },
InteriorPointArea:
{ [Function: oi]
centre: [Function],
avg: [Function],
SafeBisectorFinder: { [Function: ai] getBisectorY: [Function] } },
InteriorPointLine: [Function: ui],
InteriorPointPoint: [Function: li],
RobustLineIntersector: { [Function: ae] nearestEndpoint: [Function] },
MCPointInRing: { [Function: Ii] MCSelecter: [Function: Ni] },
MinimumBoundingCircle:
{ [Function: wi]
pointWitMinAngleWithX: [Function],
lowestPoint: [Function],
pointWithMinAngleWithSegment: [Function] },
MinimumDiameter:
{ [Function: Li]
nextIndex: [Function],
computeC: [Function],
getMinimumDiameter: [Function],
getMinimumRectangle: [Function],
computeSegmentForLine: [Function] } }

NodeJs mssql connection returning undefined from .Request()

I'm having trouble getting a working connection via nmp's mssql package.
Here's a quick look at my code:
var sql = require('mssql');
var sqlConfig = {
user: 'NodeUser',
password: 'test',
server: '10.211.55.3',
database: 'NodeJs'
}
sql.connect(sqlConfig, function(err){
if(err != null)
console.log(err);
console.log(sql);
});
Which seems to connect fine, but when I try to use it (in a route class):
var sql = require('mssql');
bookRouter.route('/')
.get(function(req, res){
var req = sql.Request();
req.query('select * from books', function(err, recordset){
console.log(recordset);
});
res.render('BookListView', {
title: 'Hello from Books',
nav: nav,
books: books
});
});
I get "TypeError: Cannot read property 'query' of undefined" on the req.query line. It seems like an issue with the connection? The only useful thing I could think to pull was the result of the "console.log(sql);" line above:
{ connect: [Function],
close: [Function],
on: [Function],
Connection:
{ [Function: Connection]
EventEmitter:
{ [Function: EventEmitter]
EventEmitter: [Circular],
usingDomains: false,
defaultMaxListeners: [Getter/Setter],
init: [Function],
listenerCount: [Function] },
usingDomains: false,
defaultMaxListeners: 10,
init: [Function],
listenerCount: [Function],
__super__:
EventEmitter {
domain: undefined,
_events: undefined,
_maxListeners: undefined,
setMaxListeners: [Function: setMaxListeners],
getMaxListeners: [Function: getMaxListeners],
emit: [Function: emit],
addListener: [Function: addListener],
on: [Function: addListener],
once: [Function: once],
removeListener: [Function: removeListener],
removeAllListeners: [Function: removeAllListeners],
listeners: [Function: listeners],
listenerCount: [Function: listenerCount] } },
Transaction:
{ [Function: Transaction]
EventEmitter:
{ [Function: EventEmitter]
EventEmitter: [Circular],
usingDomains: false,
defaultMaxListeners: [Getter/Setter],
init: [Function],
listenerCount: [Function] },
usingDomains: false,
defaultMaxListeners: 10,
init: [Function],
listenerCount: [Function],
__super__:
EventEmitter {
domain: undefined,
_events: undefined,
_maxListeners: undefined,
setMaxListeners: [Function: setMaxListeners],
getMaxListeners: [Function: getMaxListeners],
emit: [Function: emit],
addListener: [Function: addListener],
on: [Function: addListener],
once: [Function: once],
removeListener: [Function: removeListener],
removeAllListeners: [Function: removeAllListeners],
listeners: [Function: listeners],
listenerCount: [Function: listenerCount] } },
Request:
{ [Function: Request]
EventEmitter:
{ [Function: EventEmitter]
EventEmitter: [Circular],
usingDomains: false,
defaultMaxListeners: [Getter/Setter],
init: [Function],
listenerCount: [Function] },
usingDomains: false,
defaultMaxListeners: 10,
init: [Function],
listenerCount: [Function],
__super__:
EventEmitter {
domain: undefined,
_events: undefined,
_maxListeners: undefined,
setMaxListeners: [Function: setMaxListeners],
getMaxListeners: [Function: getMaxListeners],
emit: [Function: emit],
addListener: [Function: addListener],
on: [Function: addListener],
once: [Function: once],
removeListener: [Function: removeListener],
removeAllListeners: [Function: removeAllListeners],
listeners: [Function: listeners],
listenerCount: [Function: listenerCount] } },
Table: { [Function: Table] fromRecordset: [Function] },
PreparedStatement:
{ [Function: PreparedStatement]
EventEmitter:
{ [Function: EventEmitter]
EventEmitter: [Circular],
usingDomains: false,
defaultMaxListeners: [Getter/Setter],
init: [Function],
listenerCount: [Function] },
usingDomains: false,
defaultMaxListeners: 10,
init: [Function],
listenerCount: [Function],
__super__:
EventEmitter {
domain: undefined,
_events: undefined,
_maxListeners: undefined,
setMaxListeners: [Function: setMaxListeners],
getMaxListeners: [Function: getMaxListeners],
emit: [Function: emit],
addListener: [Function: addListener],
on: [Function: addListener],
once: [Function: once],
removeListener: [Function: removeListener],
removeAllListeners: [Function: removeAllListeners],
listeners: [Function: listeners],
listenerCount: [Function: listenerCount] } },
ConnectionError:
{ [Function: ConnectionError]
captureStackTrace: [Function: captureStackTrace],
stackTraceLimit: 10,
prepareStackTrace: undefined,
__super__: [Error] },
TransactionError:
{ [Function: TransactionError]
captureStackTrace: [Function: captureStackTrace],
stackTraceLimit: 10,
prepareStackTrace: undefined,
__super__: [Error] },
RequestError:
{ [Function: RequestError]
captureStackTrace: [Function: captureStackTrace],
stackTraceLimit: 10,
prepareStackTrace: undefined,
__super__: [Error] },
PreparedStatementError:
{ [Function: PreparedStatementError]
captureStackTrace: [Function: captureStackTrace],
stackTraceLimit: 10,
prepareStackTrace: undefined,
__super__: [Error] },
ISOLATION_LEVEL:
{ READ_UNCOMMITTED: 1,
READ_COMMITTED: 2,
REPEATABLE_READ: 3,
SERIALIZABLE: 4,
SNAPSHOT: 5 },
DRIVERS: [ 'msnodesql', 'tedious', 'tds', 'msnodesqlv8' ],
TYPES:
{ VarChar: [sql.VarChar],
NVarChar: [sql.NVarChar],
Text: [sql.Text],
Int: [sql.Int],
BigInt: [sql.BigInt],
TinyInt: [sql.TinyInt],
SmallInt: [sql.SmallInt],
Bit: [sql.Bit],
Float: [sql.Float],
Numeric: [sql.Numeric],
Decimal: [sql.Decimal],
Real: [sql.Real],
Date: [sql.Date],
DateTime: [sql.DateTime],
DateTime2: [sql.DateTime2],
DateTimeOffset: [sql.DateTimeOffset],
SmallDateTime: [sql.SmallDateTime],
Time: [sql.Time],
UniqueIdentifier: [sql.UniqueIdentifier],
SmallMoney: [sql.SmallMoney],
Money: [sql.Money],
Binary: [sql.Binary],
VarBinary: [sql.VarBinary],
Image: [sql.Image],
Xml: [sql.Xml],
Char: [sql.Char],
NChar: [sql.NChar],
NText: [sql.NText],
TVP: [sql.TVP],
UDT: [sql.UDT],
Geography: [sql.Geography],
Geometry: [sql.Geometry],
Variant: [sql.Variant] },
MAX: 65535,
map:
[ { js: [Function: String], sql: [sql.NVarChar] },
{ js: [Function: Number], sql: [sql.Int] },
{ js: [Function: Boolean], sql: [sql.Bit] },
{ js: [Function: Date], sql: [sql.DateTime] },
{ js: [Object], sql: [sql.VarBinary] },
{ js: [Object], sql: [sql.TVP] },
register: [Function] ],
fix: true,
Promise: [Function: Promise],
VarChar: [sql.VarChar],
VARCHAR: [sql.VarChar],
NVarChar: [sql.NVarChar],
NVARCHAR: [sql.NVarChar],
Text: [sql.Text],
TEXT: [sql.Text],
Int: [sql.Int],
INT: [sql.Int],
BigInt: [sql.BigInt],
BIGINT: [sql.BigInt],
TinyInt: [sql.TinyInt],
TINYINT: [sql.TinyInt],
SmallInt: [sql.SmallInt],
SMALLINT: [sql.SmallInt],
Bit: [sql.Bit],
BIT: [sql.Bit],
Float: [sql.Float],
FLOAT: [sql.Float],
Numeric: [sql.Numeric],
NUMERIC: [sql.Numeric],
Decimal: [sql.Decimal],
DECIMAL: [sql.Decimal],
Real: [sql.Real],
REAL: [sql.Real],
Date: [sql.Date],
DATE: [sql.Date],
DateTime: [sql.DateTime],
DATETIME: [sql.DateTime],
DateTime2: [sql.DateTime2],
DATETIME2: [sql.DateTime2],
DateTimeOffset: [sql.DateTimeOffset],
DATETIMEOFFSET: [sql.DateTimeOffset],
SmallDateTime: [sql.SmallDateTime],
SMALLDATETIME: [sql.SmallDateTime],
Time: [sql.Time],
TIME: [sql.Time],
UniqueIdentifier: [sql.UniqueIdentifier],
UNIQUEIDENTIFIER: [sql.UniqueIdentifier],
SmallMoney: [sql.SmallMoney],
SMALLMONEY: [sql.SmallMoney],
Money: [sql.Money],
MONEY: [sql.Money],
Binary: [sql.Binary],
BINARY: [sql.Binary],
VarBinary: [sql.VarBinary],
VARBINARY: [sql.VarBinary],
Image: [sql.Image],
IMAGE: [sql.Image],
Xml: [sql.Xml],
XML: [sql.Xml],
Char: [sql.Char],
CHAR: [sql.Char],
NChar: [sql.NChar],
NCHAR: [sql.NChar],
NText: [sql.NText],
NTEXT: [sql.NText],
TVP: [sql.TVP],
UDT: [sql.UDT],
Geography: [sql.Geography],
GEOGRAPHY: [sql.Geography],
Geometry: [sql.Geometry],
GEOMETRY: [sql.Geometry],
Variant: [sql.Variant],
VARIANT: [sql.Variant],
pool: { max: 10, min: 0, idleTimeoutMillis: 30000 },
connection: { userName: '', password: '', server: '' },
init: [Function] }
I can't help but notice the lack of credentials here. Any thoughts? Thanks.
Looks like an issue of asynchronisity, try doing it on the request directly, like the mssql npm example:
var sql = require('mssql');
bookRouter.route('/')
.get(function(req, res){
sql.Request().query('select * from books')
.then(function(recordset){
console.log(recordset);
res.render('BookListView', {
title: 'Hello from Books',
nav: nav,
books: books
});
}).catch(function(err){
// some error handling
});
});

How to call all javascript member functions in an array? [node.js]

I want to iterate through and call all member functions associated to "os"
var os = require('os');
var keye = Object.keys(os);
keye.forEach(f => os.f());
Prototype:
{ endianness: [Function: getEndianness],
hostname: [Function: getHostname],
loadavg: [Function: getLoadAvg],
uptime: [Function: getUptime],
freemem: [Function: getFreeMem],
totalmem: [Function: getTotalMem],
cpus: [Function: getCPUs],
type: [Function: getOSType],
release: [Function: getOSRelease],
networkInterfaces: [Function: getInterfaceAddresses],
arch: [Function],
platform: [Function],
tmpdir: [Function],
tmpDir: [Function],
getNetworkInterfaces: [Function: deprecated],
EOL: '\r\n' }
You need something like this:
Object.keys(os).forEach(function (key) {
if (typeof os[key] === 'function') {
console.log(key, os[key]());
}
});

Resources