node.js

Nodejs and update file inside zip archive

余生颓废 提交于 2021-02-19 08:01:42
问题 I want update file in zip arhive with nodejs . For example i have zip file with two files: a.zip |-a.txt |-b.txt I use archiver: var archiver = require('archiver'); var archive = archiver('zip', {}); archive.pipe(fs.createWriteStream('./a.zip')); archive.append(fs.createReadStream('./c.txt'), { name: 't.txt' }); archive.finalize(); But I have a problem, my archive is completely overwritten. As a result, I get: a.zip |-t.txt If I use: archive.file('./a.txt', { name: 't.txt' }); the result

Using puppeteer how do you get all child nodes of a node?

China☆狼群 提交于 2021-02-19 07:54:47
问题 I'm having trouble finding a way to iterate subnodes of a given node in puppeteer. I do not know the html structure beforehand, just the id of the parent element. var elemId = "myelemid"; const doc = await page._client.send('DOM.getDocument'); const node = await page._client.send('DOM.querySelector', { nodeId: doc.root.nodeId, selector: '#' + elemId }); //node.children empty //node['object'].children empty //try requesting childnodes var id = node.nodeId; var childNodes = await page._client

node ejs reference error data not defined at eval when handing data to view

前提是你 提交于 2021-02-19 07:54:06
问题 i've been closing in on a node application using express and ejs, but when i try to hand data to my view from the controller like so var myData = { theData: data }; res.render(path.join(__dirname + '/../views/index'), myData); i get a nice error ReferenceError:.. myData is not defined eval (from ejs lib) when trying to access myData in the view like so var data = <%-myData%>; or in any other way basically, i've tried stringifying the data, wrapping it in another object and stuff like that but

Can Not Set Environment Variable in NodeJS App-Windows

血红的双手。 提交于 2021-02-19 07:40:31
问题 I am learning NodeJS and I need to know how to set my production environment using process.env.___ .When I run console.log(app.get('env')); //app is express object I get output on command prompt development as environment. But if I try to set an environment variable eg. process.env.NODE_ENV , on command prompt I write : set NODE_ENV=production and then again try : console.log(process.env.NODE_ENV); I get output: undefined . I've been struggling hard and searching online but have't got a

Browsersync Couldn't open browser Heroku

谁说胖子不能爱 提交于 2021-02-19 07:34:44
问题 Browsersync: when I use it locally it's all right. When I deploy on Heroku, I have this warning: Couldn't open browser (if you are using BrowserSync in a headless environment, you might want to set the open option to false) this is my package.json : "scripts": { "clean": "rimraf dist/{css/*,js/*,images/*}", "autoprefixer": "postcss -u autoprefixer -r dist/css/*", "scss": "node-sass --output-style compressed -o dist/css src/scss", "lint": "eslint src/js || true", "lint-scss": "stylelint src

How to retrieve linked fields in Contentful query

旧城冷巷雨未停 提交于 2021-02-19 07:31:10
问题 I'm using Contentful and have a content model which uses a series of related fields. I am querying my content in NodeJS using the JS api. If I call get entries, like so contentfulClient.getEntries({ content_type: 'homePage' }) it fetches all the content of type homePage, and includes the actual field data for each related field, like so "subField": { "sys": { "space": { "sys": { "type": "Link", "linkType": "Space", "id": "#######" } }, "id": "#######", "type": "Entry", "createdAt": "2017-03

I/O performance in Node.js worker threads

时光毁灭记忆、已成空白 提交于 2021-02-19 07:17:57
问题 Here's an example with worker thread that takes ~600ms on local machine for synchronous I/O: const fs = require('fs'); const { isMainThread, Worker, parentPort, workerData } = require('worker_threads'); const filename = './foo.txt'; if (isMainThread) { (async () => { console.time('!'); await new Promise((resolve, reject) => { const worker = new Worker(__filename, { workerData: filename }); worker.on('message', resolve); worker.on('error', reject); worker.on('exit', (code) => { if (code !== 0)

Prevent system calls in Node.js when running untrusted user code

不问归期 提交于 2021-02-19 06:58:03
问题 I am currently considering issues of running user-supplied code in node. I have two issues: The user script must not read or write global state. For that, I assume I can simply spawn of a new process. Are there any other considerations? Do I have to hide the parent process from the child somehow, or is there no way a child can read, write or otherwise toy with the parent process? The user script must not do anything funky with the system. So, I am thinking of disallowing any system calls. How

Node.js binary to PDF

筅森魡賤 提交于 2021-02-19 06:48:19
问题 I have got a express server, which creates a pdf file. I am trying to send this file to the client: const fs = require('fs'); function download(req, res) { var filePath = '/../../myPdf.pdf'; fs.readFile(__dirname + filePath, function(err, data) { if (err) throw new Error(err); console.log('yeyy, no errors :)'); if (!data) throw new Error('Expected data, but got', data); console.log('got data', data); res.contentType('application/pdf'); res.send(data); }); } On the client I want to download it