#StackBounty: #javascript #node.js #angular #typescript error on encoding large file on nodejs side after sending file from angular-side

Bounty: 50

I am getting the file on server side as console.log(body)

{ fieldname: 'image',
  originalname: '21329726_1866651723650020_188839340_o.jpg',
  encoding: '7bit',
  mimetype: 'image/jpeg',
  destination: './pics/',
  filename: '5146c9818ff517c426e34ad84ff3513f',
  path: 'pics/5146c9818ff517c426e34ad84ff3513f',
  size: 94093 
}

and then encoding by const base64Data = body.buffer.toString("base64")

but for small size file it works well ,But for large file it creates problem, It is not encoding properly.

I think the problem is due to, it starts encoding before it receives the full file.

Please give me some proper way to do this.

This is my github link click here


Get this bounty!!!

#StackBounty: #javascript #node.js #session How to make session last maximum of 30 days using client-sessions duration and activeDuration

Bounty: 50

According to https://github.com/mozilla/node-client-sessions#usage

var sessions = require("client-sessions");
app.use(sessions({
  cookieName: 'mySession', // cookie name dictates the key name added to the request object
  secret: 'blargadeeblargblarg', // should be a large unguessable string
  duration: 24 * 60 * 60 * 1000, // how long the session will stay valid in ms
  activeDuration: 1000 * 60 * 5 // if expiresIn < activeDuration, the session will be extended by activeDuration milliseconds
}));

I want my users’ sessions to be active for a maximum of 30 days. If I set duration to 30 days and activeDuration to 30 days, I think I’ll end up with 60 day long sessions.

If I set duration to 15 days and activeDuration to 15 days, won’t a user who logs in and then does nothing at all be logged out in 15 days (not that I expect that kind of user behavior, but is my assumption correct?)

All I want is for every time a user comes to the site to get 30 days before they need to re-login. How do I get that behavior?


Get this bounty!!!

#StackBounty: #node.js #mongodb #nosql mongodb lookup with collection and dynamic query output

Bounty: 50

I have some dynamic query for a collection

var condition = dynmic_query
db.collection.find(condition)

is giving me an output

now what I need whatever I am getting from previous query need to lookup with an another collection.

I am scared if this is not possible yet in mongodb

[https://jira.mongodb.org/browse/SERVER-22497]

I did some google but not getting idea how to achieve this one

I have to execute this query in node.js

Please help

Thanks


Get this bounty!!!

#StackBounty: #node.js #nosql #object-document-mapper #couchbase Actively maintained Object Document Mapper (ODM) for Couchbase (altern…

Bounty: 50

I am new to NodeJS and Couchbase and am looking for a reliable Object Document Mapper (ODM) for Couchbase. The most popular one, it seems, is Ottoman but Ottoman’s GitHub repository is not being maintained actively. Its own Website is out of date and I cannot find adequate community question and answers regarding my problems (I cannot install its package on my project error-free on a Windows system).

Are there any recommended alternative ODMs to Ottoman that are reliable and popular?


Get this bounty!!!

#StackBounty: #javascript #node.js #webpack #mocha #mocha-webpack mocha-webpack not finding tests

Bounty: 100

I can’t seem to figure how to get mocha-webpack to detect tests in my folder. I’m running the following command:

mocha-webpack --webpack-config test/server/webpack.config-test.js

webpack.config-test.js

var nodeExternals = require("webpack-node-externals")
const path = require("path")

function resolve(dir) 
{
    return path.join(__dirname, "..", dir)
}

module.exports = {
    context: path.resolve(__dirname),
    resolve: {
        extensions: [".js"],
        alias: {
            "vue$": "vue/dist/vue.esm.js",
            "@": resolve("src"),
        }
    },
    target: "node", // webpack should compile node compatible code
    externals: [nodeExternals()], // in order to ignore all modules in node_modules folder
}

If it helps, I’m also using vue-cli, so there are already webpack configs, and maybe I could just import one of them then do slight changes.


Get this bounty!!!

#StackBounty: #node.js #nosql Any Alternative ODM for Couchbase Other Than Ottoman?

Bounty: 50

I am new to NodeJS and Couchbase and am looking for a reliable ODM for Couchbase. The most popular one, it seems, is Ottoman but Ottoman’s GitHub repository is not being maintained actively. Its own Website is out of date and I cannot find adequate community question and answers regarding my problems (I cannot install its package on my project error-free on a Windows system).

Are there any recommended alternative ODMs to Ottoman that are reliable and popular?


Get this bounty!!!

#StackBounty: #javascript #angularjs #node.js #karma-jasmine #e2e-testing Angular.js+nw.js+webpack+karma+jasmine how to test

Bounty: 50

I have a nw.js native application with angular.js inside. My app bundled with webpack and contains native node.js modules. My entry point is index.js file that I organized like this:

var gui = require('nw.gui');
var angular = require('angular');
require('./app.css');

// other modules

var myApp = angular.module('myApp', [
    'ngRaven',
    'ngMaterial',
    'ngMessages'
]).constant(
    'fs', require('fs')
)

require('./services')(myApp);
require('./directives')(myApp);
require('./factories')(myApp);
require('./filters')(myApp);
require('./controllers')(myApp);
require('./app.js')(myApp);

My webpack config looks like this:

const path = require('path');

const config = {
    entry: [
        './app/index.js'
    ],
    output: {
        path: path.resolve(__dirname, 'app'),
        filename: 'bundle.js'
    },
    devtool: "source-map",
    target: 'node-webkit',
    module:{
        // css, html loaders
    },
    node: {
        os: true,
        fs: true,
        child_process: true,
        __dirname: true,
        __filename: true
    }
};

module.exports = config;

So every dependency include Node.js native modules like fs, path, child_process bundled in one big file bundle.js that i include in html and then package my nw.js app. So my app structure looks like:

my_project:
--app
----controllers
------welcome
--------welcome.js // Page controller
--------welcome.html // Page HTML
------index.js // here I include each page controller
----app.js // My angular app initialization
----index.js // here I include all dependencies 

I’m trying to run tests with this structure. I tried karma+jasmine, karma+mocha, tried different configurations, my last one looks like:

module.exports = function (config) {
    config.set({
        basePath: '',
        frameworks: ['jasmine'],
        files: [
            'app/bundle.js',
            'app/**/*spec.js'
        ],
        exclude: [],
        preprocessors: {
            'app/bundle.js': ['webpack']
        },
        reporters: ['progress'],
        port: 9876,
        colors: true,
        logLevel: config.LOG_INFO,
        autoWatch: true,
        browsers: ['ChromeHeadlessNoSandbox'],
        customLaunchers: {
            ChromeHeadlessNoSandbox: {
                base: 'ChromeHeadless',
                flags: ['--no-sandbox']
            }
        },
        singleRun: true,

        webpack: {
            // you don't need to specify the entry option because
            // karma watches the test entry points
            // webpack watches dependencies

            // ... remainder of webpack configuration (or import)
        },

        webpackMiddleware: {
            // webpack-dev-middleware configuration
            // i.e.
            noInfo: true,
            // and use stats to turn off verbose output
            stats: {
                // options i.e.
                chunks: false
            }
        }
    });
};

But my tests still not see the angular application.

describe('Welcome page', function() {
    beforeEach(angular.mock.module('WelcomePageCtrl'));
});

P.S I don’t require exactly karma and jasminne, so any solution will be appreciated. I just want to cover my project with tests


Get this bounty!!!

#StackBounty: #node.js #node-cluster #sticky-session Nodejs Clustering with Sticky-Session

Bounty: 50

const cluster = require('cluster');
const http = require('http');
const numCPUs = require('os').cpus().length;

if (cluster.isMaster) {
  console.log(`Master ${process.pid} is running`);

  // Fork workers.
  for (let i = 0; i < numCPUs; i++) {
    cluster.fork();
  }

  cluster.on('exit', (worker, code, signal) => {
    console.log(`worker ${worker.process.pid} died`);
  });
} else {
  // Workers can share any TCP connection
  // In this case it is an HTTP server



  var sticky = require('sticky-session');
  var express = require('express');
  var app = express();

  app.get('/', function (req, res) {
      console.log('worker: ' + cluster.worker.id);
      res.send('Hello World!');
  });


  var server = http.createServer(app);
      sticky.listen(server,3000);

  console.log(`Worker ${process.pid} started`);
}

I looked up the documentation for nodejs clustering and sticky-session
and another stack overflow answer regarding this

  var cluster = require('cluster');
  var http = require('http');
  var sticky = require('sticky-session');
  var express = require('express');
  var app = express();

  app.get('/', function (req, res) {
      console.log('worker: ' + cluster.worker.id);
      res.send('Hello World!');
  });


  var server = http.createServer(app);
      sticky.listen(server,3000);

If the above snippet is run without forking it works fine but else never works as shown in the clustered example above in which the threads are started but server is never initialised .

I read there is alternative of sticky-cluster can somebody give a proper authoritative answer on this topic which will be useful for people looking for the same and the another main issue comes with this is the app.locals object which is used to store variables for an app instance and the occurrence multiple server instances causes this to break as values will be different across different instances so this approach causes a big issue and app breaks so .When answering please don’t copy paste some code please give a detailed answer detailing the approach its benefit and short comings.

I am not looking for a answer that is limited to using sticky-sessions nodejs module, I welcome all other approaches in which all cores of the processor are used and but ensuring session continuity .

If it involves RedisStore or MongoDb store its ok,What I want to know is about a standard approach in case of nodejs application with clustering with session continuity

https://github.com/indutny/sticky-session

https://nodejs.org/api/cluster.html

https://stackoverflow.com/a/37769107/3127499


Get this bounty!!!

#StackBounty: #javascript #node.js #sails.js Sails.js – sails route with regular expression

Bounty: 50

I am working with sails 0.11.2. Here i am facing an issue with defining a route pattern that will start with ‘/source/< anything goes here>/< must not contain .js extension at the end>

Regular Expression : /^/source.*(?<!.js)$/i in java script in working fine, but when i am putting this in sails route.

Getting Error : Invalid regular expression: /^r|/^/source.(.*)(?<!.js)$/i/?$/: Invalid group .

Syntax in Route :

    'r|/^/source.*(?<!.js)$/i' : {
    controller: 'pageController',
    action: 'pageAction'
  }    

Please help me out, what is wrong and how to correct it?


Get this bounty!!!