How do I develop npm installed packages along with my app? - node.js

I'm working on my application. In parallel, I'm working on updating(and adding to) a couple of the npm installed submodules at the same time.
In my package.json dependencies I have:
"zeke-bootstrap": "git://github.com/twilson63/zeke-bootstrap.git",
When I do npm install, it goes and checks out the repository and puts it under node modules just fine. My question is how to I setup this directory so that I can use git, and do commits, and eventually a push to send my changes in my dependent directory back up to github?
Thanks,
Fred

You can checkout your git repo in the node_modules folder under the same folder name as your module and node will automatically use it. However, I don't think its a very good idea. Modules are modules because they are meant to be developed separately.

Related

Ignore a specific package while installing dependencies using 'npm install'

I have a node package react-native-push-notification for which i have made some changes in the packages to fulfil my requirement. But every time i do a npm install the new (original package without my changes) package overlaps with my current package.
Is there any way i can restrict npm install to ignore my modified package? And also i want to push this package to git.
Any lead will be highly appreciated.
If I understand you correctly you have made some changes to the already existing node package react-native-push-notification and you would rather use your own version of it than the original.
You have a couple of options:
In package.json change react-native-push-notification to point to your git repo (e.g. your fork on github). This is not ideal since it makes semver problematic. But it works.
Rename your fork of the package and use that directly from npm. E.g. rename to react-native-push-notification2 or even better, use a scoped package name e.g. #yournick/react-native-push-notification and publish that to npm. Change your package.json to use this package instead.
Convince the authors of the original package to incorporate your changes. This is the ideal solution, but might be difficult to get your patch merged etc.
patch-package is exactly what you're looking for: https://github.com/ds300/patch-package
It will preserve your changes even after running npm install.
The best way to handle this would be to fork the repo https://help.github.com/articles/fork-a-repo/.
This way, you have control of the contents of the package.
Then update your package.json with your repo address.
I also would recommend not pushing your packages to Git. Packages are already under version control (in their own repo) and pushing to Git just bloats your repo for no reason.
Yes you can do it very easily. Fist of all go to the plugin GitHub repository then fork it to your profile. Before if you want to install this plugin from the direct repo, you have to run this command -
npm i https://github.com/zo0r/react-native-push-notification.git
But after successful fork, it will install the modified files that you have made changes and the command should be -
npm i https://github.com/YourUserName/react-native-push-notification.git
and boom your modified files never will change.

Nodejs use a project in another project

I have a beginner question concerning nodejs.
I'm working on two different nodejs projects, let's say project A and project B.
And I would like to use the functionalities of project A in B.
How can I do it??
I was thinking about using git submodules. But is there a possibility to use project A as a node_module. that means that the users only have to update it if a new version of it is available?
Thank you
No need to use git submodules - you can use npm to install a module directly from a git remote url, or directly from GitHub.
e.g.:
npm install <git remote url>
npm install githubname/reponame
See the npm install docs for details.

Packaging a Wordpress Theme made with Roots (Sage)

I am just getting into the GIT / GULP / Bower workflow. I am basically a complete noob. I have a WordPresstheme being developed on my local machine via MAMP.
Say I wanted to package it up and open it on another Machine, either with Mamp or Wamp.
I don't think I can zip the theme folder with all the NPM Nodules, so what would be the best steps to take to avoid any or minimal bugs.
If you're using git you need to commit and push your changes to a remote repo. Then pull the repo down to the second machine and re-run the build process.
In roots sage 8 that will mean:
Installing bower and npm globally (if you haven't already done so)
Installing the bower npm packages for you project
Running the gulp build task
In Sage the npm modules, bower packages and dist folders are ignored by git because they are listed in .gitignore.
In general it's usually considered good practice NOT to commit any dependancies to your projects repo.

How to check out a JHipster project in multiple development environments

I'm evaluating JHipster; it looks great for rapid development!
Maybe a novice question: I see that the generated .gitignore ignores certain things, e.g.
/node/**
/node_modules/**
So, if I check in the generated project to a repository, and then some other developer in my team checks it out in his environment, the project would not work in his environment. Would it?
Was curious to know how to handle this. Thanks.
Since your git repo won't track node packages, others using your git repo will need install node.js, then run npm install to download all the node packages.
It's similar to them having to have java and maven installed on their environment.
Update: A developer will run 'git clone '. The source (not including node or bower) will be on their workstation. Once they've installed node.js, they'll run 'npm install' and the node directories will be created automatically for your project by downloading them from the Internet. That way you don't need to keep all your node libraries in your own git repository ...just their package name and version in the package.json file (similar to maven dependencies in pom.xml).
No one should commit the node_modules or bower_components to git, what you would do is share the project like you share the maven projects.
Write in the read me what needs to be done to get them ready, for example the installation of yo, bower, grunt or gulp and generator-jhipster.
What is very nice about liquibase, each developer can have his own version of the database, and every commit has its own database version.
What we our team does, if a developer adds something to node js package.json then we mention it in the comment: npm install needed and the same applies for bower.
That way you keep all your environments clean, and if you would like to install continuous integration like "Jenkins or Teamcity" then you make sure Jenkins is building rebuilding the whole project.

Build and deploy framework for NodeJS

I've been looking around for a Java maven equivalency for NodeJS but can't really seem to find one so I'm posting this question to see whether there're a combination of tools/framework I can use to build and deploy Node. The specific tasks I'm looking for is:
Being able to grab dependent modules for a checked out code NodeJS project (for ex. Express or stuff like that)
Set up a private repository for NodeJS modules for in-house projects
Package with dependencies and make releases of Node projects to a repository (sorta like war)
Deploy a release to a remote box and fire up Node
Any help would be greatly appreciated!!!
Npm does most of that for you.
Dependency handling:
Create a package.json for your project (see required contents or use npm init)
Commit it along your project files, this will be your dependency tracking
npm install will sort out and download all dependencies
Deploying:
Upload/push your files to the server
Either send the node_modules folder along or run npm install on the server
To use your private libraries you'll need to either upload the modules folder or publish them (see below)
Private/local libraries:
Create the library anywhere you want (e.g. ~/Projects/mylib)
go to the mylib folder and run npm link
go to the project's folder and run npm install mylib
Now your local library is symlinked into your project's node_modules
To set up a private repository for your modules, follow these instructions

Resources