Nodejs's npm is very handy. So I decide to use it for my company's project.
But the problem comes .My company forces us to develop in a closed network , I can only access internal web site and other stuff...
So I wonder how to solve this problem, when you want to use npm, but outside network is disallowed.
Any help will be appreciated. Thank all.
The only possibility you have is to use npm on a machine which can navigate and then copy the npm modules in the development machine.
Generally there are specific rules in the network that allow the team to do that things but still block another network sites.
How are you handling the downloading of third parties tools as Downloading google chrome, downloading an ide? Use the same system.
I guess that the system admin provide you those tools and/or enable specific rules so you can download it by yourself.
Otherwise you can download the npm package with your phone or another device with total network access and just copy it to your computer after that you must push it to the internal network repository otherwise your co workers should do the same thing to get the npm packages...
Or once you've downloaded it for the first time, point the npm package to local repository.
https://docs.npmjs.com/getting-started/what-is-npm
You will need to have the internet to download the packages initially and keep them updated as dependencies. Good Luck.
You can use URLs, local paths and even GIT URLs as your dependencies in you package.json. I don't see why you couldn't create a pseudo npm in your own network with those methods and then just allow other developers to npm install the dependencies from there.
Related
I'm pretty new to javascript development so apologize in advance if this seems obvious. I'm trying to build a private npm package that is not accessible to users.
However, I am able to see other npm package code that's supposedly not open-source by going into their respective node_modules subdirectory. So I'm wondering what the difference is between public and private npm packages since one can view the source code via node_modules folder either way.
Thanks for the help!
The privacy setting only affects wether a package can be published to a package registry or not and which people are able to access the package (e.g using restricted packages for custom company packages which are used in several projects). So "private" helps in preventing a package from being accidentally published and restricts the set of users who can access the package.
This is not a way to somehow obfuscate or hide your code from people whom you shared the package with!
While there are ways to achieve what you want to do, it's not as simple as you might think, as JS itself is not a compiled language and ca. (One way would be to write the code you want to hide in another, compiled language, e.g. C, and then call your C library via JS, basically using JS just as a wrapper)
TL;DR: If you grant users access to an NPM package they will be able to see the code of the package, end of the story. You can only decide who will be able to see/access the package by setting the privacy (public/private/restricted) of the package.
I tried so but I have a 'require is not defined' error. I can't find information about that, can someone enlighten the noob in me please?
It's possible, but you have to be careful. Trying to require() a package means that node will try to locate its files in your file system. A chrome extension only has access to the files you declare in the manifest, not your filesystem.
To get around this, use a module bundler like Webpack, which will generate a single javascript file containing all code for all packages included through require(). You will have to generate a separate module for each component of your chrome extension (e.g. one for the background page, one for content scripts, one for the popup) and declare each generated module in your manifest.
To avoid trying to setup your build system to make using require() possible, I suggest starting with a boilerplate project. You can check out my extension to see how I do it.
An updated answer for 2022
Short answer: yes, you can require/import packages. Rather than going through the tedious work of setting up & configuring a bundler like Webpack on your own (especially if you have no experience with them), there are now build tools you can use to create the boilerplate "scaffolding" for a Chrome extension:
Extension CLI -- this one is well-documented and you can also reference the source code of some Chrome extensions that have used this tool (READ: learn how others have set up their code).
Chrome Extension CLI
Benefits of using them:
New projects are initiated with a default project file structure. Super helpful.
They support modern Javascript (ES6, ES2021), so modules work fine.
They already have bundlers integrated and pre-configured (Webpack in both above cases I think). You therefore don't need to install and configure any on your own.
You can use npm as normal to install any packages/dependencies you need.
Then of course, let the official documentation for Chrome Extensions guide you through the rest.
It's not possible to require node modules directly within a chrome extension. However, it is possible to bundle node applications and packages into the browser for use with your extensions. See here for more: Is it possible to develop Google Chrome extensions using node.js?
Yes, It is possible with esm npm packages.
require is commonjs module loader.
Browser doesn't support commonjs modules system
so that this error showed.
Method 1:
Run npm init -y and add "type" :"module" in your package.json.
create path.js file
add this line in path.js
const fullPath = await import.meta.resolve("npm-pkg-name");
const path = fullPath?.match(/(/node_modules.*)/)[0];
console.log(path);
add this line inside package.json
"path": "node --experimental-import-meta-resolve path.js",
Copy console output text. Replace package name with this copied path.
Method 2:
Install other npm package to find and replace
npm packages' virtual path to real path so that chrome browser will find it.
Install Path-fixxer
Add this line in path.js
import setAllPkgPath from "path-fixxer";
setAllPkgPath();
then run command : npm run path.
Now open browser to test it.
I have a simple CLI application written in Javascript using Node that is for internal use by a small team. It runs in the Linux terminal as a CLI app. The app consists of a single ".js" file and requires a few Node packages. The problem I face now is how to deploy it to our internal team using a simple method that fits with our routine process of keeping end user computers updated.
Our app needs to be installed once per workstation / laptop and to be available to all users on that computer. Any user should be able to open a terminal and enter the command to run the app.
It seems a lot of people have discussed using Javascript for shell programming, but this issue of deploying the completed app is not widely discussed. I have not found anything on the topic. So far I have been recommended solutions that are appropriate for either development environments or web servers.
This app is not a web app and it is not deployed on a server. It needs to run offline. I am also not asking about developing or maintaining the app on a development workstation.
The installation process should ideally be as about simple as installing a shell script in /usr/local/bin and setting permissions so all permitted users on a computer can run it. We are looking for an installation method like this:
copy the Javascript file only once to each computer (to a location on the $PATH) and make sure the Node packages are available globally on that computer.
I specifically want to avoid having to do an npm install for each user account on each computer.
I also want to avoid having to update Node packages for each user account on each computer.
A developer will keep the app updated so it is always compatible with the latest version of the Node packages, and all computers it is deployed on will always have the latest versions of those packages installed.
One specific problem I encountered is discussed here, but the answers assume a different set of requirements (such as the need for "multiple applications running on different package versions").
For those requirements, if the actual problem is solving the EACCESS error (you should edit the question to include that information), then you should look at the permissions of all directories, and make sure that the user account that manages node packages on each computer has correct permissions.
One way to do that is to give /usr/local a special group, set the sticky bit with chmod (see man chmod), and use chgrp -R on the existing tree.
Then make the installing account a member of that group, and don't use sudo for npm install -g.
(Never using sudo for installations into /usr/local has the additional advantage that you can't accidentally install something somewhere else, for example because you didn't set paths in this local package source correctly.)
We are using these two approaches for similar deployments:
the programs live on a specific network mount. All users can run the same package from there. The developer only updates this package. No copying to local machines.
we use a simple deployment script which runs on all machines on logon. It pushes and copies the latest version to the local machine.
Recently I was on holiday with limited internet connectivity. I was developing an application in node.js when I suddenly needed some NPM packages. This put a severe halt in the development and I was forced to wait until I could go online to download said packages and continue development.
Is it possible to mirror the whole npm registry locally on my computer? How to do that?
It should be possible seeing as online mirrors of the main registry exists. Where do they gather all packages from?
This is what npm-offline could do for you. npm-offline could cache modules, you would just need to create a script that ensures you have the modules that you want cached.
I'm primarily a front-end coder but I'm not a stranger to server-side programming or the command line. Regardless I've still got a lot to learn about setting up servers and whatnot so I was wondering if anyone could help me put together some steps for setting up CouchDB on (preferably) ubuntu.
That's my main goal but I'd also like to get the 'JS3' environment going if possible. See this post for more info.
The things I struggle with most are knowing what packages I need to install and how to get it so I can work in my browser on localhost. Thanks for any pointers you can give me.
Packages are very dependant on the Operating System Flavor you use. On Freebsd you could go with
cd /usr/ports/www/helma ; make install clean
cd /usr/ports/databases/couchdb ; make install clean
and you have all the relevant software on your server. Then you need jQuery beeing hosted somewhere. Helma's Jetty Webserver can handle that for you.
For Ubuntu I read it now comes with a couchdb package sou you can just do
sudo apt-get install couchdb