node.js

Integrate all Angular2 and Hapi routes

不想你离开。 提交于 2021-02-08 07:39:44
问题 Situation I'm developing a web application that uses Hapi server for REST calls and multi-page Angular2 website client-side. Hapi serves all Angular2 files to the client with: let serverDirPath = path.resolve(__dirname); server.route({ method: "GET", path: "/{param*}", config: { auth: false, handler: { directory: { path: path.join(serverDirPath, "../client"), index: true } } } }); Calling the server root successfully returns "index.html", and after that the Angular2 website works perfectly!

How to Avoid Sequelize JS Associations Including both the Foreign Key and the Included Object

跟風遠走 提交于 2021-02-08 07:38:35
问题 How can I avoid showing both the foreignKey that sequelize creates and the eagerly fetched object through includes? I have the following model structure: FormEntry: owner: User createdBy: User modifiedBy: User formEntryData: [FormEntryData] I modeled it after reading through SequelizeJS docs and came up with the following: const User = sequelize.define('user', { id: { type: Sequelize.BIGINT(20), field: 'user_id', primaryKey: true }, emailAddress: { type: Sequelize.STRING(256), field: 'email

Azure function run code on startup for Node

帅比萌擦擦* 提交于 2021-02-08 07:37:25
问题 I am developing Chatbot using Azure functions. I want to load the some of the conversations for Chatbot from a file. I am looking for a way to load these conversation data before the function app starts with some function callback. Is there a way load the conversation data only once when the function app is started? This question is actually a duplicate of Azure Function run code on startup. But this question is asked for C# and I wanted a way to do the same thing in NodeJS 回答1: You can use

axios equivalent to curl --upload-file

梦想的初衷 提交于 2021-02-08 07:36:46
问题 I'm trying to upload a gif to Gfycat using their public API. This is done using cURL on the command line with: curl https://filedrop.gfycat.com --upload-file /tmp/name I attempted to convert this to Node.js using axios: axios.post("https://filedrop.gfycat.com", { data: fs.createReadStream("/tmp/name") }).then(console.log).catch(console.log); but an error with the message <?xml version="1.0" encoding="UTF-8"?>\n<Error><Code>PreconditionFailed</Code><Message>At least one of the pre-conditions

node 'net' module ECONNREFUSED error

岁酱吖の 提交于 2021-02-08 07:33:56
问题 I'm looking at this page: http://nodejs.org/api/net.html#net_net_createconnection_options_connectionlistener Running the code from the page: var net = require('net'); var client = net.connect({port: 8124}, function() { //'connect' listener console.log('client connected'); client.write('world!\r\n'); }); client.on('data', function(data) { console.log(data.toString()); client.end(); }); client.on('end', function() { console.log('client disconnected'); }); and I'm getting the error: events.js:72

node 'net' module ECONNREFUSED error

情到浓时终转凉″ 提交于 2021-02-08 07:32:25
问题 I'm looking at this page: http://nodejs.org/api/net.html#net_net_createconnection_options_connectionlistener Running the code from the page: var net = require('net'); var client = net.connect({port: 8124}, function() { //'connect' listener console.log('client connected'); client.write('world!\r\n'); }); client.on('data', function(data) { console.log(data.toString()); client.end(); }); client.on('end', function() { console.log('client disconnected'); }); and I'm getting the error: events.js:72

Running Playwright in Azure Function

廉价感情. 提交于 2021-02-08 07:26:12
问题 I'm trying to run a simple Azure Function that would enter page and generate a PDF depending on what is visible in a browser. I created a NodeJS 12 Azure Function with Linux Consumption Plan (B1). I set PLAYWRIGHT_BROWSERS_PATH to 0 . Function code looks like this: const { chromium } = require("playwright-chromium"); const baseUrl = "http://someurl"; const targetPage = "/action/"; module.exports = async function (context, req) { const browser = await chromium.launch(); const page = await

Running Playwright in Azure Function

Deadly 提交于 2021-02-08 07:23:25
问题 I'm trying to run a simple Azure Function that would enter page and generate a PDF depending on what is visible in a browser. I created a NodeJS 12 Azure Function with Linux Consumption Plan (B1). I set PLAYWRIGHT_BROWSERS_PATH to 0 . Function code looks like this: const { chromium } = require("playwright-chromium"); const baseUrl = "http://someurl"; const targetPage = "/action/"; module.exports = async function (context, req) { const browser = await chromium.launch(); const page = await

Confused about Sequelize associations

喜夏-厌秋 提交于 2021-02-08 06:57:25
问题 I just found Sequelize as a good ORM framework to use in my node + MySQL webapp. But when I was designing my database tables, I got so confused about Sequelize associations. Just think about user and system notification in a webapp as a very simple case: The site has many users The site would send notifications to some or every users, and the same notification just save as one record Users could know any notification he/she received is read or not(by a read date) Then I design 3 tables as

GRPC - nodejs DNS resolution failed

ぐ巨炮叔叔 提交于 2021-02-08 06:57:21
问题 I'm working with a GRPC service hosted with HTTPS and self-signed cert. When I connect using syntax like: const client = new productService('https://grpc-server-xxx.com:9090', grpc.credentials.createInsecure()) I am getting the error like this { Error: 14 UNAVAILABLE: DNS resolution failed at Object.exports.createStatusError (C:\grpc\node_modules\grpc\src\common.js:91:15) at Object.onReceiveStatus (C:\grpc\node_modules\grpc\src\client_interceptors.js:1209:28) at InterceptingListener._callNext