How to stream to a zip using NodeJS and Browserify - javascript

I'm new to JavaScript / NodeJS so forgive me for what's likely a basic question. But I'm trying to understand something fundamental.
We've a project structured like so
Bottom layer is made up of a re-usable NodeJS SDK
This is being bundled by Browserify
The bundle is used with a local index.html (via JavaScript calls)
The current task I'm working on involves writing code in the SDK to
Read data from a http REST API
Format this data
Create a zip on disk
Write the formatted data to the zip
Then I need to write code in the index.html
To supply a path
Kick off the above steps to create a zip
As a starting point I've been playing with the standard NodeJS fs module. However when I browserify the code
import fs from 'fs';
translates fs to {}. There does seem to be a separate module browserify-fs that'll allow me to support fs. But this issue has made me question the approach I'm taking.
Is fs a good option to use for a browser?
How common is it for browser JavaScript to support streaming to zip? i.e. As opposed to downloading a pre-existing zip from a http server.
Appreciate this question is open ended. But I'm curious to hear what the community thinks.

Related

why is Requiring mongoose from local file is not working?

So I have the code
Directory/app/script.js:-
// MongoDb
// Connect to MongoDB through Mongoose
const mongoose = require('mongoose')
mongoose.connect('mongodb://localhost:27012/profiles')
// Requiring the Schemas
const SignIn = require('MongoDb/Models/profiles.js')
console.log(SignIn)
So what is wrong in the code. The console in the web says that require is not defined. Can you help me with how to go about it.
There are two reasons you might get this error. Since you said
The console in the web says
I expect it is the first reason in your code
You are running the code in a web browser
Node.js is a stand-alone environment for running JavaScript. It is not a browser extension.
To run Node.js code, save it in a file with a .js file extension, then run it with:
node yourFile.js
If you want Node.js code and browser code to interact then the typical way is to write a server in Node.js that hosts a web service. Express.js is a popular way to do this. You can then use Ajax to make HTTP requests to that web service.
For bi-directional communication (as opposed to the request/response of Ajax) look at Socket.io.
You are using ECMAScript modules
Node originally used CommonJS modules which use module.exports and require.
Recent versions also support ECMAScript modules which use export and import.
Either switch to using import instead of require or change your configuration to use CommonJS modules.

Wheren can I find the source code of the pre-implemented NodeJs packages?

Ist there a possibility to view the source code of NodeJS packages like fs or crypto??
Are they implemented in Javascript or is their implementation part of the C++ kernel of NodeJS?
I tried to look for getRandomBytes on GitHub at https://github.com/nodejs/node (it's a function that's part of the crypto-module), but there are no search results.

How to create/import bare node.js module (without express) with IntelliJ

Default node.js module gets created with express, adds all the dependencies and forces me to remove all these files afterwards.
Isn't there any other way to create simple node.js project without express while keeping all remaining seetings (node_modules marked accordingly etc.)? Was trying to google around but with no luck.
Please vote for the related request on YouTrack: https://youtrack.jetbrains.com/issue/WEB-12988

What javascript parser sould I use to re-implement jsCoverage in JavaScript for node?

I really like code-coverage reports for my code in node.js.
I've already created a node.js module that can inject instrumented code (and mock our require statements) called requiremock
I'm using that in my other module nodecoverage together with the binary version of jsCoverage (windows) to generate code coverage reports, injecting instrumented versions of code with requiremock.
The problems with using jsCoverage are
It needs compilation for the platform, because it's written in C(++), I would like to implement it in JavaScript so it can be used on any platform without compilation.
It writes the instrumented versions of code as files on disk. With requiremock I can generate the instrumented JavaScript files in memory and run those when the original file is required.
jsCoverage does not report code coverage correctly when using function hoisting, and I use that a lot in node.js
So my question is:
What JavaScript parser written in JavaScript should I choose to reimplement jsCoverage as a node.js module?
I have to be able to know the linenumber of the code in the original file, and also know what whitespacing was like.
Try esprima. It's awesome. Also node-cover potentially already does have what you need

Is there a node module that will compile a project to a client side file?

I'm new to node, but so many client-side open source projects use it that I am assuming there is a way to compile a node project to be compressed into one minified file that is ready for client-side usage. The open source project I'm building is using node for it's nice module and testing support, but all of the code is meant to be run on the client.
I've seen projects like this: https://github.com/mape/connect-assetmanager
But what I'm not sure of, is whether node-specific constructs like export and module are removed or supported, so that there aren't problems on the client side?
You should look at http://requirejs.org/
It replaces and extends require for both node (server-side) and browser side. It also supports merge and minification
Just came across this:
https://github.com/substack/node-browserify
Awesome project!!
You are incorrect. Node is server-side only. Perhaps you have a bit of a misunderstanding what Node is and isn't.
Nodejs is basically the Google Chrome V8 Javascript engine, packages as an executable that can run on a console. Javascript code written for node could run on the client though, but it's not as simple as you may think.
What functionality that you currently have on the server do you want to run on the client? Are you just looking for a minifier like yui compressor?

Categories

Resources