Node.js

23

Solutions

72

Contributors

Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Node.js' package ecosystem, npm, is the largest ecosystem of open source libraries in the world.

Share tech news, updates, or what's on your mind.

Sign up to Post

I'm trying to run this example here https://github.com/squallooo/MT5 (of an HTML5 application)

It needs to run on Node.js - I am unfimilar with Node.js. (though ok with IIS)

I have downloaded Node.js and installed it. I have downloaded the ZIP file from GitHub.

Can someone please give me a step-by-step to enable me to open/run this one-page web file?

A demo is here http://mainline.i3s.unice.fr/
(pretty cool if you're a musician)

Thanks
0
Webinar: MongoDB® Index Types
LVL 2
Webinar: MongoDB® Index Types

Join Percona’s Senior Technical Services Engineer, Adamo Tonete as he presents “MongoDB Index Types, How, When and Where Should They be Used?” on Wednesday, July 12, 2017 at 11:00 am PDT / 2:00 pm EDT (UTC-7).

I am trying to connect to MongoDB in mongoDBatlas from my javascript but I keep getting the following error.

MongoError: connection 5 to isaaccluster-shard-00-02-yng8g.mongodb.net:27017 closed
    at Function.MongoError.create (C:\Users\558642\ga\js-dc-5\11-crud-and-dbs\assignment\todo\node_modules\mongodb-core\lib\error.js:29:11)
    at TLSSocket.<anonymous> (C:\Users\558642\ga\js-dc-5\11-crud-and-dbs\assignment\todo\node_modules\mongodb-core\lib\connection\connection.js:202:22)
    at Object.onceWrapper (events.js:293:19)
    at emitOne (events.js:101:20)
    at TLSSocket.emit (events.js:191:7)
    at _handle.close (net.js:511:12)
    at Socket.done (_tls_wrap.js:332:7)
    at Object.onceWrapper (events.js:293:19)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:191:7)
    at TCP._handle.close [as _onclose] (net.js:511:12)


Here's my code
const express = require('express')
const hbs = require('express-handlebars')
const mongoose = require('mongoose')
const bodyParser = require('body-parser')

mongoose.connect('mongodb://XXXXXXXXXXXX@isaaccluster-shard-00-00-yng8g.mongodb.net:27017,isaaccluster-shard-00-01-yng8g.mongodb.net:27017,isaaccluster-shard-00-02-yng8g.mongodb.net:27017/<DATABASE>?ssl=true&replicaSet=IsaacCluster-shard-0&authSource=admin')

const itemEntry = require('./models/toDoEntry.js')
const app = express()

app.get('/', function( req, res ) {
	itemEntry.find({}, function( err, itemEntries ) {
			res.render('todoList',

Open in new window

0
I am working on a project using, node, Webpack, babel and ES6.

Inside my project I've created a module which I want to load into the project at runtime.

The end result I'm looking for is that when the application will have different features. The code for each feature will be in a module.

The user can then enable or disable certain features at runtime.

How can I do this?
0
Hi All,

I have a 2 node hyper v cluster running a bunch of virtual machines.

I can successfully connect to the cluster via failover cluster manager with no issues. I have run the validate cluster tool which passes successfully also

When I right click on a node and select 'connect' I get the console window as expected, however it only works on hyper v host 1 not hyper v host 2.

When I also try and connect to the problem host via Hyper-V manager I receive the following:

Any suggestions?
Capture.PNG
Capture1.PNG
0
Hello experts,

Is there any way to handle cuss words in
 Nodejs application.

Thank you
0
I have node installed on my laptop.

I have a folder that I want to use for my testing of angular:

C:\programfiles\angularjs

node is installed here:

C:\programfiles\nodejs

From within the nodejs directory I want to be able to start an http server like this:

C:\programfiles\nodejs> node server.js

which would start the http server and just wait, listening on some port like 5000

then, in a web browser like Chrome, I want to navigate to localhost and load an HTML file:

localhost:5000/test.html

But the test.html file resides at this location:

C:\programfiles\angularjs\test.html

I've been doing lots of reading on "express" and "connect" middleware, but I just can't seem to make it work.


For example:

I ran the following:

npm install connect -g

and

npm install serve-static -g

and then ran "node server.js"

server.js:

var connect = require('connect');

var serveStatic = require('serve-static');


connect.createServer( serveStatic("../angularjs") ).listen( 5000);

Open in new window


gives this error:

TypeError: connect.createServer is not a function
0
Below is my  code,Can   anyone please  tell me why my window.onload function  does not  work? I am javascript newbie

// performs an AJAX get call asynchronously and puts the result into an element
function ajaxAsync(url, elementId) {
    var ajax = createAjaxRequestObj();
    ajax.onreadystatechange = function() {
        if (ajax.readyState == 4) {

//Here is my window.onload function
            window.onload = function(){
                document.getElementById(elementId).innerHTML = ajax.status == 200 || ajax.status == 304 ? ajax.responseText : "(an error has occurred - please try refreshing the page - " + ajax.status + ")";
            }
            if (finishLoad) {
                finishLoad();
            }
        }
    }
    ajax.open("GET", randomizeUrl(url), true);
    ajax.send(null);
}

Open in new window

1
best way to have users and roles and authenicate based on these users and  roles  and based in nodejs apis?
0
Hi Team,

I have a 2 node hyper V cluster running on windows server 2012 R2 ,i wanted to convert present LUN to CSV but i am not getting the option.

CsvJPG.JPG
0
Hello expert,

 I have a piece of code which i used it in other, is it a correct way of doing it or any other way we can have


function addZero(i) {
	if (i < 10) {
		i = "0" + i;
	}
	return i.toString();
}

Open in new window


//---  create current date in YYYY-MM-DD HH:MM:SS format ---//
function curDate() {
	var d = new Date();
	var crDate = d.getFullYear()
	+ '-' + addZero(d.getMonth() + 1)
	+ '-' + addZero(d.getDate())
	+ ' ' + addZero(d.getHours())
	+ ':' + addZero(d.getMinutes())
	+ ':' + addZero(d.getSeconds());
	return crDate;
}
}

Open in new window

0
Transaction Monitoring Vs. Real User Monitoring
LVL 1
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Hello expert,

Any tools to analysis the code  like coding standards on angularjs and nodejs side

Thank you

Roy
0
Hi guys,

I am trying to figure out the best way to automatically pull down certain files from a server i was thinking a cron job would be the best way, i was wondering is there anything wrong with my script here and would there be a better way to do it?

The files are json files, and they are playlists on machines that could be currently in use

Something like
if(playlist.json file == error message){
//download json file again
}

It will also need to check which playlist is currently playing (before toggling each playlist using the script) and ensure it is set back to that same playlist after toggling each

[2:01]  
***

Something like
var count = 0;
if(playlist.json file == error message && count<3){
//download json file again
count ++;
//load playlist into threadqueue
}else{
//must be issues downloading the playlist so revert to default playlist and flag us
0
Can anyone please  help? I  am trying to extract  an ID 254162  from  URL  http://localhost:9080/company_add.jsp?id=254162. I have  tried  to  write  as seen  below but I  when I  do  console.log,Java script  return /company_add.jsp only.Anything I am missing?.Thank you
     
var url=window.location.pathname;
            var  UrId=url.substring(url.lastIndexOf('=') + 1);

Open in new window

0
I am trying to login a user using an api request which passes the jwt token in the querystring, followed by a location.href call to redirect the user to a protected url(html page). On the server side for my jwt setup method I am setting up jwt with the following code:

app.use(expressJwt({secret: process.env.AUTH_KEY,
  credentialsRequired: true,
  getToken: function fromHeaderOrQuerystring (req) {
    if (req.headers.authorization && req.headers.authorization.split(' ')[0] === 'Bearer') {
        return req.headers.authorization.split(' ')[1];
    } else if (req.query && req.query.access_token) {
      console.log('the access token = ' + req.query.access_token);
      return req.query.access_token;
    }
    return null;
  }}).unless({path: [{ url: '/api/forgotpassword/', methods: ['PUT'] }, 
  { url: '/forgotpassword/', methods: ['GET'] }, 
  { url: '/api/login', methods: ['POST', 'PUT'] },
  { url: '/login', methods: ['GET'] },
  { url: '/index', methods: ['GET'] },
  { url: /\/css\/*/, methods: ['GET'] },
  { url: /\/js\/*/, methods: ['GET'] },
  { url: /\/images\/*/, methods: ['GET'] },
  { url: '/resetpassword', methods: ['GET'] },
  { url: '/api/resetpassword', methods: ['PUT'] }]} ));

Open in new window


Even though I can see the code gets executed for the getToken method, tied to the expressJwt object, and the return gets executed to return the access_token, I am still receiving the error indicating "No authorization token was found". Is there any additional plumbing required to integrate express-jwt and passport? Just to show the location.href is passing the url successfully, here is one of the url's: http://localhost:3000/testlist/1?access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiZmlyc3RuYW1lIjoiS2V2aW4iLCJsYXN0bmFtZSI6IlRheWxvciIsInJvbGVzIjoiYWRtaW4iLCJpYXQiOjE0ODg3NTM2OTIsImV4cCI6MTQ4OTM1ODQ5Mn0.4_XUXPAU13LtGRXqADuQpW0-jW2wErNlftjo4mttH7U, Plus I am seeing it in the getToken call. This is incredibly confusing. What could I be missing here? I follow this example to code the authentication, https://blog.hyphe.me/token-based-authentication-with-node/. Any help would be greatly appreciated.
0
I'm looking for information on node.js. I am planning to implement an e-learning solution for a school system, and a partner suggested we use node.js as a platform, but since moodle is in php, and node.js is javascript, I'm confused. I have also never used this before, and don't understand what it is for.
0
can somebody help us lighting on sessions on client side on angularjs2 side. For Authentication we use passport     authentication node js. is it required to handle session  from the client side.. Let us know if any questions...
0
Hi ,
I have written a code for mongoDb Update.
                var _data = responses.devices;
                var existingUser = {
                    'ipackages': _data.ipackages
                }

                Users.save(existingUser, function(err, result) {
                    if (err) {
                        console.log("Error : " + err)
                    }
                    console.log("## USE UPDATED Successfully ## ");
                        /* REDIS CACHE */
                        redisClient.hmset(key.toString(), newUser, function(err, reply) {
                            if(err){
                                console.log('Error : '+err)
                                //throw err;
                            }else{
                                console.log('Data : '+reply)
                            }
                        });

                    res.send({'message':'User Updated Successfully'})
                })

Open in new window


But after compilation i am getting this error.

TypeError: Users.save is not a function
    at D:\Ad\AdServer\routes\users.js:112:23
    at Query.<anonymous> (D:\Ad\AdServer\node_modules\mongoose\lib\model.js:3398:16)
    at D:\Ad\AdServer\node_modules\kareem\index.js:259:21
    at D:\Ad\AdServer\node_modules\kareem\index.js:127:16

Open in new window


Please help me out.
0
Hello ,
  I have a JS function  that I used to send notification. However, I am getting some time out from database . I would like to queue the request .

Then have some process that iterate thru the  queue and send the notification.  The queue is always getting updated with new request

the 'pushService.sendNotifications' call is just another function that format the message and send

Can you give me some suggestion on how to implement it,,,


function sendNotifications(req, res) {
  pushService.sendNotifications(req.headers.apikey, req.body)
  .done(function (results) {
    log.debug('notification results: ' + JSON.stringify(results, null, 2));
    res.status(200).send(results);
  }, function (error) {
    log.debug('push failed outright: ' + JSON.stringify(error, null, 2));
    res.status(error.code).send(error);
  });
}

Open in new window


Thanks
0
I am familiar with JavaScript and JQuery. However I need to run some code for an application called OneFlow which is used for submitting order details. The script is in GitHub here:
https://github.com/Oneflow/oneflow-sdk-js

I wish to run submit-order.js. However it uses the command "require" at the top which I understand is part of NodejS.

Can someone please explain the simplest way to run this script and import NodejS? WIth JQuery it is simply a matter of referencing the latest JQuery file. Can I do something similar for NodejS?

Incidentally I need to run this on a Windows 2008 server.
0
Industry Leaders: We Want Your Opinion!
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

We are designing a web app build with JavaScript, NodeJS, Express, React/Redux, Bootstrap.

We have many pages where a user clicks on a link in a table or presses a button to download a file. The team that has done most of the work on the app triggers the download in a few steps in order to make sure the file being downloaded actually exists, otherwise an error is displayed. They use a popup browser window to deliver the file to browser user. For some reason, the popup is being suppressed by Safari and blocked by Chrome.

Can you look at the code and pinpoint why the popup is being blocked or perhaps point me to a tutorial on how to trigger a file download without using popups at all?

Our table:
			<BootstrapTable condensed={true} bordered={false}
				options={{ sizePerPageList: [10, 15, 20, 25, 30, 50, 100, 250, 500] }}
				data={uploadedFiles} striped={true} hover={true}
				pagination={true} search={true} searchPlaceholder='Filter'>
				<TableHeaderColumn dataField='fileName'	dataAlign='left' dataSort={true}
					width='50' dataFormat={this.downloadFileLink.bind(this)}>FileName</TableHeaderColumn>
			</BootstrapTable>

Open in new window


Methods called when cell is clicked. rGet is a custom helper. All it does is send a Get request to our API (written in ExpressJS) to request the  file. One thing that I find interesting is that the coding team builds a link that the popup will use. I am guessing they do it to tell the browser that the popup belongs to our website and not a 3rd party site. I am correct? If so, why is this strategy not working and the popup is blocked by both Chrome and Safari?



Open in new window

0
We have build a simple dropbox-like web application using JavaScript/NodeJS/Express. It talks to our API routes, also written in JS. The UI is based on Bootstrap + commercial UI template. We used React/Redux architecture for web front end.

We have a button that uploads a file the user has selected, by calling our our API. We noticed that often our API returns status 200 or status  201 for successful requests. Is there a reason the status is randomly 200 or 201?

We used to check for success by checking for:
if (res.status === 200)

What is the best practice? Is there a clever way to check for all types of success status? Or should we always hard code:
if (res.status === 200 || res.status === 201)
Is there a way to avoid code duplication?
0
I am using $cordovaFile.writeFile to save a zip file to iPad. The zip file contents are send by Node server and passed to the below function in data parameter.

var saveZipToiPad = function (data, fileName) {
      console.log('Saving file ' + fileName + ' to iPad');
      return $cordovaFile.writeFile($rootScope.dataDirectory, fileName, data, true)
        .then(function (result) {
          console.log('Data saved to device');
          return true;
        })
        .catch(function(err) {
          console.log(JSON.stringify(err));
        });
    };

Open in new window


This code works absolutely fine for small files (lets say a zip file with 5-6MB size). However, when it runs for larger files like 50MB size, the app crashes (app closes). In the xcode logs, it gives the below error

2016-10-09 21:21:09.454 MyApp[3168:700308] Received memory warning.
Message from debugger: Terminated due to memory issue

Open in new window


Is there some kind of memory limit beyond which writeFile would not be able to save files? I could not find anything like that in the docs.

How can I make my app work for large sized files, 50-60MB size?
0
Hello all,
    I am having trouble finding an absolute, bare bones from scratch tutorial. I have written an app in node JS that writes directly to and reads from MongoDB, I made a reverse proxy that is written in nodejs  that points my domain subfolders to different ports for parse-server and parse dash (eg: site.com/parse, site.com/dash).

I see tutorials on the parse wiki and things of that nature, but they just do a section at a time, and do not seem to tie things together in a way that makes sense to me. Is there any sort of step by step tutorial that anyone knows of that starts with the basics, just as, you make a file called something.js, you put require =("parse") or whatever it needs,  it creates the server port, then shows how to use an html page to write data to parse, and then read it back to the page. I am not sure why I can not grasp how parse works vs just simply writing to mongo, but the rest of my pals who are working on a project that I am trying to help on are all using it and I just can not find a tutorial that explains exactly why you would want / need parse over just writing to mongodb directly as I had before. I would like to know, but can not find good enough explanations, even in their official documentation, it just is not "clicking" for me. Even just a single application that uses node, parse, express, and has a form that writes and reads something like a user registration form, or just simple form data and then displays it would make all the …
0

Node.js

23

Solutions

72

Contributors

Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Node.js' package ecosystem, npm, is the largest ecosystem of open source libraries in the world.

Top Experts In
Node.js
<
Monthly
>