Questions tagged [node-js]

68166 questions
1

votes
1

answer
778

Views

Can I use JQuery mobile with Nodejs

I would like to build a mobile web app and I am a bit curious of what technology I can use.I am thing of writing the server side in Nodejs but I am not sure if I can combine it with Jquery mobile?
user1850254
1

votes
1

answer
22

Views

What is the proper method to stop/exit a node.js route?

I have a node.js / express route that firstly checks if a cookie is set or not. This works well, now i want to exit the route if no cookie is set. My route lookes like this app.post('/VerEmpresas', function(req, res) { if(req.cookies.cookieName1) { var cookie = JSON.parse(req.cookies.cookieName1); i...
Ingolf Krauss
0

votes
1

answer
16

Views

Using Request to post from NodeJS

I am running into an issue with posting a json doc via request from my nodeJs app. The problem is for me how to pass the json doc to post. Here is what works for me const options = { url: 'http://localhost/message/send/981f1507-2df2-4011-8f55-5460897fcde6', method: 'POST', json: true, body: { "mes...
MisterniceGuy
0

votes
0

answer
5

Views

PHP Site and NodeJS Websocket Application behind the same Nginx server/config

I have a development server that is running Nginx and serving a PHP website. Below is the working nginx config. cat /etc/nginx/nginx.conf user www-data; worker_processes auto; pid /run/nginx.pid; include /etc/nginx/modules-enabled/*.conf; events { worker_connections 768; # multi_accept on; } http {...
Andrew Odendaal
0

votes
0

answer
4

Views

java.net.SocketTimeOutException from Node.js

I am trying to implement Sign up feature on Android App. And I get java.net.SocketTimeoutException error: And I get this from Node.js server: It doesn't show any errors but --ms-- shows it took a long time. In other words, it means timeout error as well. This is routes/member.js where I get this err...
Chanjung Kim
0

votes
0

answer
5

Views

How to display an image from mysql using Express

I have a sql table 'animals' where there are blobs images. I found out how to upload images but not how to display them. I would like to display the image which is called 'Dog' in my table. Here is my code, where I print the result of my blob img. let sql = 'SELECT * FROM animals WHERE file_name=\'D...
Julien
0

votes
0

answer
4

Views

Cannot convert video file to audio file inside AWS lambda function using Node js

I cannot convert a video file into an audio file inside AWS lambda function using Node JS. While running my lambda function it doesn't throw any error it executes without any error. But the audio file size is still 0 MB size. I am not able to find bugs or any issues in my code. Here is my code, cons...
Arun
1

votes
1

answer
471

Views

Documentation or examples for ''newSession'' and 'resumeSession' events in TLS module for node.js

I am having a hard time finding documentation and examples for the 'newSession' and 'resumeSession' events for the TLS module in node.js. Any links or help in this direction is appreciated. I need to know more about these events in order to implement a fault resistant tls connection in node.
digster
1

votes
1

answer
785

Views

Node.js supertest post gzipped data

I'd like to write a test to post up some zipped data to a url as follows, but it doesn't work: zlib.gzip('foo_bar_data', function (err, buffer) { request(app) .post('/foo/bar') .set('Content-Encoding', 'gzip') .send(buffer) .expect(200) .end(function(err, res){ if (err) return done(err); //various o...
user1328174
1

votes
1

answer
1.9k

Views

Node.js Buffers and Binary Files

I'm reading a file using Node and attempting to send it as a multi part MIME post, but having problems with the file appearing corrupt at the receiving end. I read the file and prepare it for sending like so: fs.readFile("before.png", function(err,data) { // Snip content += data.slice(0,data.lengt...
1

votes
1

answer
1.1k

Views

Image storage performance on file system with Nodejs and Mongo

My Node.js application currently stores the uploaded images to the file system with the paths saved into a MongoDB database. Each document, maybe max 2000 in future, has between 4 and 10 images each. I don't believe I need to store the images in the database directly for my usage (I do not need to t...
adamK
1

votes
1

answer
1.4k

Views

async.parallel() - last function not being called

For some reason the 'yyyyyyyyy' string is never printed when I use async.parallel() as per below. Why is this? I thought that the last function would be called once the other two have been called. var async = require('async'); async.parallel([ function() { console.log('xxxxxxxxxxx'); }, function() {...
Warrick FitzGerald
1

votes
1

answer
4.1k

Views

Caching mongoose objects with Redis

Is it possible to cache, say, mongoose document obejcts in Redis, perhaps for implementing a write-back or write-through cache with timeout-based cache flush mechanisms? P.S.: I am familiar with mongoose-redis-cache, but I guess it supports only lean queries, which do not quite serve the purpose her...
ixaxaar
1

votes
1

answer
2.5k

Views

Error handling using fork

In my below code error is not getting catched by Parent.js which is thrown by processChildOne.js // Parent.js var cp = require('child_process'); var childOne = cp.fork('./processChildOne.js'); var childTwo = cp.fork('./processChildTwo.js'); childOne.on('message', function(m) { // Receive results fro...
user87267867
1

votes
2

answer
1.4k

Views

Balancing slow I/O in a fast stream read stream

In node.js I have a read stream that I wish to reformat and write to a database. As the read stream is fast and the write is slow the node.js queue could be overwhelmed as the queue of writes builds up (assume the stream is gb's of data). How do I force the read to wait for the write part of the cod...
user1305541
1

votes
3

answer
2.3k

Views

passing an array from express to jade client side javascript

I have this jade template: html head script(type="text/javascript" src="https://www.google.com/jsapi") script(type='text/javascript') google.load("visualization", "1", {packages:["corechart"]}); google.setOnLoadCallback(drawChart); function drawChart() { var data = google.visualization.arrayToDataTa...
otmezger
1

votes
3

answer
1.2k

Views

Express: composing middleware

I want to move a series of app.use() calls into its own module. The easiest way to encapsulate this is to expose a function(app) in the exports, but I feel that handing over the app object is too much of an opaque interface. I would like to expose a middleware to be app.use()'d from outside the modu...
slezica
1

votes
2

answer
570

Views

Python tcp socket client

I need to have a tcp socket client connected to a server to send data and receive. But this socket must be always on and i cannot open another socket. I have always some data to send over the time and then later process the answer to the data sent previously. If i could open many sockets, i think...
balsagoth
1

votes
1

answer
2.6k

Views

Is it safe to use and update global variables in NodeJS?

I have a node server for loading certain scripts that can be written by anyone. I understand that when I fire up my Node server, modules load for the first time in the global scope. When one requests a page, it gets loaded by the "start server" callback; and I can use all the already loaded modules...
Gasim
0

votes
0

answer
27

Views

Node failed to lookup view “error” in Express/react app

I am working on my app and it worked a few hours ago. But now when I start it, I get the following error. There is no /views directory in /lib, but there is in my src/. It contains error.jade. I have tried everything. Deleting /lib, reinstalling everything... Error: Failed to lookup view "error"...
vemund
0

votes
0

answer
28

Views

How to convert a javascript file to .exe file

i googled this question, but all are saying about html+css+js and with mixed answers. But i have only javascript file which i need to convert into exe file with arguements passing into it and i need to use this into my automation framework on a case as a step to execute a case, which is written in c...
mmar
1

votes
2

answer
76

Views

axios-mock-adapter not matching url as expected

I used to use axios-mock-adapter with great success, but the last few times i've tried to use it, my routes never seem to match and it is still trying to execute a real endpoint. Why is this unit test still making a call to example.com and returning a 404? I would have expected it to return a 500. t...
Catfish
2

votes
0

answer
18

Views

How to connect securely to mongo docker container with mongoose through a node container for production?

Here is my docker-compose.production.yml. version: "3.7" services: ############################## # Back-End Container ############################## backend: container_name: mern_backend init: true environment: - MONGO_URI=mongodb://root_username:[email protected]_db:27017/mern_db?authSource=...
yaharga
0

votes
0

answer
6

Views

Validate an uri which contains mustache template with Joi

I'm trying to validate an uri which can contains a mustache syntax (https://mustache.github.io/) : {{ key }} So it can look like this (which is an invalid URI in the first place) : http(s)://whatever.com/.../{{ key }}/... I'm using Joi, it seems that Joi.string().uri() cannot allow more letters. I a...
Hugo Da Roit
0

votes
0

answer
3

Views

Not able to invoke the data in chain code in node js

I have this format input in my chain code. How to write the function in node js [ { "sequenceid":"sid001", "sno":"1", "present":"0", "end":"500" }, { "sequenceid":"sid002", "sno":"100", "present":"150", "end":"1000" } ]
sasi
1

votes
1

answer
3k

Views

Need to send data back from a NodeJS server to a JQuery client

I'm trying to send some files and data back from a NodeJS server to a client that works in JQuery. I use res.sendfile() to return files from the NodeJS server, but that downloads the file on the client computer. I only want to send the file back to the JQuery code (Written in Typescript) and enable...
EternallyCurious
1

votes
2

answer
796

Views

Handle webservices with post method type in ExpressJS using http-proxy

I am developing a website using express.js and ember over node. I have hosted my website in a ubuntu server and this website uses a set of webservices (which are running in some other different server). To avoid cross domain issue (while calling webservices from website), I am using http-proxy as f...
1

votes
2

answer
519

Views

Node.js stack trace info

I'm looking for info on Node.js error stacks, and why layers seems to be missing from them. We are throwing an error when a user is not found in our Mongo database. We are using Mongoose as an ODM. Our error management is pretty simple - when the call to Mongoose comes back empty, we create a new er...
CargoMeister
1

votes
1

answer
132

Views

Foreign key pointing to wrong identifier

I am having a peculiar problem when using association in Sequelize. I have two models Rock rock_id : { type: DataTypes.BIGINT, allowNull: false, primaryKey: true, autoIncrement: true }, rock_mode_id : { type: DataTypes.BIGINT }, with associations: associate: function(models) { rock.hasOne...
Ian McCullough
1

votes
1

answer
989

Views

How do I send images and javascript files to the browser using Node js

I have created a Node.js server that worked well when the Javascript was part of the HTML page. I moved the JS to another file and added some images. Now it won't load the images or the JS into the browser. However, the web page renders perfectly when I open the web page directly. This is what my se...
vamsiampolu
1

votes
1

answer
657

Views

Node.js fs.readFile vs jQuery $.getJSON - which is faster?

I'm working on a program running in Node-Webkit, and I use jQuery for many other tasks. Now I have a settings.json file that I need to load upon the start of the program, and I was thinking about how to load it. So either I use the node.js fs functions to read the data from the file and then use JS...
woubuc
1

votes
2

answer
4.7k

Views

Heroku Deploy Error: Cannot get Node App running after Deploy : Cannot find module '/app/web.js'

I have a node.js app using Express and MongoDB (mongoose). It runs perfectly fine locally. I deployed it to heroku seemingly without a problem, but when I try to actually launch the app it crashes. The heroku log says this: Error: Cannot find module '/app/web.js' I am new to this, so any help would...
user3416321
1

votes
2

answer
1.3k

Views

NodeJS How to organize Callbacks in a controller

I am new to NodeJS and coming from a PHP environment I am trying to figure out how to work with multiple callbacks. I do understand the basics about callback and I think it does make sens when writing modules. My problem is when comes the time to use those modules how to organize all the callbacks....
Frank6
2

votes
2

answer
29

Views

Assign Dynamic api reponse to typescript interface

I am new to typscript and nodejs. I am trying to assign a response get it from restful api call to typescript interface. I dont want to use Object.keys or Obejct.values to get the required data but trying to use typescirpt interface for that . Here is the response , // this is dynamic in nature {...
devmk
0

votes
0

answer
26

Views

Nodejs with Mongoose returns one object value instead of multiple in an array

data=[{ locId: '332wn', locadetails: [ { loc: 'ny', status: true }, { loc: 'ca', status: null }, { loc: 'tx', status: null } ] }] I have following query that is trying to find all the locdetails that have open value as null or false Loc.find({'locId': id}, {'locadetails' : {$elemMatch: {'status': {...
J. Davidson
1

votes
1

answer
21

Views

How to combine 2 endpoints express.js into a new one

I have 2 existing endpoints /balance /transactions What is the best way to create a new one /balance-and-transactions and not rewrite existing code For instance: a('/balance', () => { foo() }); b('/transactions',() => { boo(); }); newendpoint('/balance-and-transactions', () => { foo(); boo(); });
newbie
1

votes
1

answer
2.1k

Views

How to read user input in node.js for simple calculations

How can I read user input from the command line in node.js for simple calculations? I'v been reading http://nodejs.org/api/readline.html#readline_readline and http://nodejs.org/api/process.html#process_process_stdin but I can't use my input for simple things like console.log(input). I know these are...
David
1

votes
2

answer
1.8k

Views

Node “ReferenceError: require is not defined” when executing a Function object

I'm trying to execute a Function object which is essentially the same as the following pseudo-code: var testF = new Function("x","y", "var http = require('http');"); testF('foo','bar'); And get: ReferenceError: require is not defined Do I need to somehow add something that reloads the require module...
Scott Graph
1

votes
1

answer
455

Views

Replicating string.format() of C# in JavaScript without numeric placeholders

String.Format method of C# allows you to keep "Replaces one or more format items in a specified string with the string representation of a specified object." string text = "select {0},{1},{2} from {3} where {4};" var result = String.Format(text, "col1","col2","col3","table","col1 > 10"); after this...
SharpCoder
1

votes
1

answer
1k

Views

Simulate an ECONNRESET error on a Node.js net.Socket instance

I'm writing some unit tests and I'd like to simulate a connection loss (ECONNRESET) on a net.Socket instance as part of one of the tests. What would be the best way to go about doing this? Thanks
9point6

View additional questions