Monday, 12 June 2017

One of the problems with using Expo development when the React native

When I was in the use of Expo development project, the first execution NPM run ios will be submitted to the errors, and then execute once is normal.

Excuse me, what's the solution?

As shown in figure:

Error screenshot

Error is as follows: › npm run ios

react-native-starterkit@0.1.0 ios /Users/****/work/react-native-starterkit

react-native-scripts ios

10:09:56: Starting packager...

10:10:09: Starting simulator...

10:10:30: Failed to start simulator:

Error: Process exited with non-zero code: 60

Exiting...



via 祝梓毅

How to enable print media emulation in headless Chrome?

Is there a way to enable simulated device mode or emulated print media mode in headless Chrome in Linux?

It can be done manually in DevTools like so:

Enable print media emulation

The goal is to take a full-page screenshot in emulated print media mode without injecting or modifying any CSS. I'm already able take screenshots of web pages via Node.js, but not in emulated print media mode. I've searched, but am also unable to find a helpful CLI switch.

Example:StackOverflow print emulation

How to do this programmatically via CLI or Node.js? Is it even possible?



via Drakes

Node.js - How to return after all asynchronous calls have finished

As shown bellow, I am pushing the object link_to_json returns into an array allShirts declared in html_to_json.

However, the console.dir on the third last line and the return value of html_to_json logs an array of undefined references. Which I presume is because console.dir and return is executed before link_to_json functions finished.

How do I ensure the return value of html_to_json is a filled up allShirts array?

//Go to individual links and scrape relevant info
const link_to_json = (link) => {
    request(link, (err, res, body) => {
        if (!error_handler(err, res, link)) {
            const $ = cheerio.load(body);
            const shirt_detail = $('.shirt-details').find('h1').text();

            const Title = shirt_detail.substr(shirt_detail.indexOf(' ') + 1);
            const Price = shirt_detail.substr(0, shirt_detail.indexOf(' '));
            const ImageURL = $('.shirt-picture').find('img').attr('src');
            const URL = link;

            return new Shirt(Title, Price, ImageURL, URL);
        } else return {};
    });
}

//Crawl through all individual links listed in Root
const html_to_json = body => {
    const allShirts = [];
    const $ = cheerio.load(body);

    $('.products').find('a').each((index, val) => {
        allShirts.push(link_to_json(rootURL + $(val).attr('href')));
    });

    console.dir(allShirts); // <--- HERE
    return allShirts;
}



via Ja. L

Having an issue with nodemailer and postfix

I'm receiving this error when I try to run nodemailer

{ Error: 139776600639296:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:../deps/openssl/openssl/ssl/s23_clnt.c:794:
code: 'ECONNECTION', command: 'CONN' }

as shown in this snippet

'use strict';
const nodemailer = require('nodemailer');

// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
    host: 'smtp.localhost',
    port: 465,
    secure: true, // secure:true for port 465, secure:false for port 587
});

// setup email data with unicode symbols
let mailOptions = {
    from: '"Fred Foo 👻" <foo@blurdybloop.com>', // sender address
    to: 'bar@blurdybloop.com, baz@blurdybloop.com', // list of receivers
    subject: 'Hello ✔', // Subject line
    text: 'Hello world ?', // plain text body
    html: '<b>Hello world ?</b>' // html body
};

// send mail with defined transport object
transporter.sendMail(mailOptions, (error, info) => {
    if (error) {
        return console.log(error);
    }
    console.log('Message %s sent: %s', info.messageId, info.response);
});

I cannot figure out here I'm going wrong with this. I left off the auth info on purpose as it said it would assume it had been authenticated already. Any help would be greatly appreciated - I've been scratching my head at this for days. Thanks!



via Zach Hill

Automatically Emit watchPosition() with socket.io without JS Interval

I'm looking for a way to listen in for when watchPosition() gets a new gps coordinate and then emit this automatically without using a javascript interval to blindly keep emiiting the values of watchPosition() with or without a change in the device's location.

Basically, update the latitude and longitude only when the device's location changes.

Thanks in advance!



via William Ebuka Okafor

node.js not printing to console

I am trying to use sockets in my api. However I could not see the logs in the console.

The only output I see is:

[nodemon] restarting due to changes...
[nodemon] starting `node server.js`
We are live on8000

Here is my server.js file:

// server.js
const express        = require('express');
const MongoClient    = require('mongodb').MongoClient;
const bodyParser     = require('body-parser');
const app            = express();
const port           = 8000;

var server = require('http').createServer(app);
var io = require('socket.io')(server);

const db = require('./config/db');

app.use(express.static(__dirname + '/../app'));
app.use(bodyParser.urlencoded({ extended: true }));


MongoClient.connect(db.url,(err,database) =>{

    if (err) return console.log(err);

    //check below line changed
     require('./app/routes')(app, database);
    app.listen(port,() => {
        console.log("We are live on"+port);
    });

    app.get('/', function(req, res){
      res.sendFile(__dirname + '/index.html');
    });


    io.on('connection',function(socket){
      console.log('client connected');

      socket.on('disconnect', function () {
        console.log('disconnect');
      });

    });

})

and the index.html is:

<!DOCTYPE html>
<html>
  <head><title>Hello world</title></head>
  <script src="/socket.io/socket.io.js"></script>
<script>
  var socket = io();
</script>
  <body>Hello world</body>
</html>

I see Hello world on the web browser, but I could not see 'client connected' on the console log.



via Teja Nandamuri

keep string between two words node js express

I have a string like:

var str = saGDJGJDJGlgk abc_start asjdgjgjgdfjakgfja abc_end csjhgfhsgfgfugvgjdj abc_start djkhfjwhjfgwjgkfvvg abc_end.

I'm displaying this string in my browser using:

res.send('/page/+result);

I want to filter out result such that only the content which starts at abc_start and end at abc_end remains. How do I do that in node.js?

For eg: output: abc_start asjdgjgjgdfjakgfja abc_end abc_start djkhfjwhjfgwjgkfvvg abc_end

I tried using : str.split('abc_start').pop().split('abc_end').shift();

But I'm not gettting desired output.Please help.



via user8151624