Build and deploy framework for NodeJS - node.js

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

Related

How to publish yarn workspace with root package.json dependencies?

I'm trying to publish one (yarn) workspace from a monorepo to npm repository, and include root project's dependencies in the published package. The setup is as follows:
package.json (contains shared dependencies, eg. single version of React to be used by all workspaces)
library/ (this is the one I want to publish, for consumption outside of this monorepo, the published package.json should contain the root dependencies as well as library local)
library/package.json (contains library specific dependencies)
app1/ (application that uses library)
app1/package.json (contains app local dependencies, and depends on library)
app2/ (application that uses library)
app2/package.json (contains app local dependencies, and depends on library)
So what I want to do, is to cd library and yarn publish. What I expect to happen is that the published package will work exactly the same way it works for my monorepo local apps. The problem is that yarn doesn't merge-in the dependencies from the monorepo's root package.json, and the published package's package.json only contains library local dependencies, from library/package.json. So when anyone installs this published library package, it will be broken because it imports modules from packages (dependencies) not listed in library/package.json.
Do I really need to write a custom publishing shell script that merges the root package.json's dependencies into library/package.json before running yarn publish?
The only type of dependencies that you can reliably put in a workspace root are dev dependencies.
Each package should declare it's dependencies in it's package.json file respectively.
What yarn does during installation is that it now looks at all the dependencies in all your workspace packages to create a single lock file and it won't put redundant dependencies in the package node_modules folder.
How you publish your workspace is up to you. I typically write a small Node.js script to run the publish command line for each package. Depending on what you put in your workspace you might want to version and/or publish your packages independently, this will give you that flexibility.

Is it possible to avoid local node_modules in js projects?

I am exploring nodejs and js frameworks. I noticed that when I create a project, for example with vue
vue init webpack my-project
I get a HUGE directory named node_modules containing a lot of things not related to my project. Newbie in this field my only wish is to gitignore this folder or better, put it somewhere else.
Is it common to have local modules to a project? Is there a way to install all these dependencies globally or in a dedicated environment (e.g Python virtualenv)?
The directory does contain libraries that are required by your project - and their dependencies. From my experience, the dependencies of the libraries I'm using are about 3/4 of the folder size.
You can install a library globally using the -g switch of npm, I'm not sure if vue has similar option. But this is not recommended - the point of installing libraries with your project is that the project will remember which libraries belong to it, those are saved in package.json.
You could copy the node_modules directory to the root of your hard-drive and merge it with other node_modules directories, but you're risking that you'll mix different library versions that way, so this is not recommended.
Unless you're running low on free space, just leave it be. Remember to add the node_modules to .gitignore if you're using git.
In short, node_modules is a place where all your project dependencies are stored. And allows you to use these dependencies in the code if you want to and allows for the modules itself to have it own dependencies if any.
And it is very common or rather always the case when a local node_modules folder is created.
You can install dependencies globally by doing npm install -g module_name command via your CLI. But these may cause the issue if the global paths are not configured properly.Also, it is not advisable to keep all the required dependencies by an application in global context.
If you do not want some dependencies to be part of your production environment you can install them as dev dependencies via npm install--save-dev module_name command. These(normal & dev dependencies) will be installed when a developer clones your project and run npm install locally to run the project and run tests. But to ignore these from being installed on production you can execute npm install --production command, this will make sure that only dependencies required for your code to run will be installed in the node_modules folder.

Node.js project deployment without internet

What is the best way to deploy Node.js project to the machine without access to the internet? For example in a private network? Is there any option to make one package containing all of dependencies for the project?
in order to deploy a project, you don't need to download anything from the internet- you need it only for running npm install when building the project. if all dependencies are already there, you can just run it.
if you need it also for building the project, you can create a local npm repository and put in there all relevant dependencies

How to do a manual install of Node js package dependencies

I am rather new to Node but am working on a project behind a very restrictive firewall so I cannot use npm to install packages (no proxy either). I am trying to use express and have been able to include it by just storing the files locally and requiring the local file path but I do not know how to structure the project so that node can find and include all of the dependencies for express (which I also have manually downloaded from github and stored locally within the project). Does anyone know how to do a completely manual global or local install of individual node dependency packages?
Simply download the files and place them in a 'node_modules' folder in the root of your app. Then use 'npm init' to create a package.json. Add your dependencies in the dependencies list in that file.
Then run simply 'npm install'.

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.

Resources