Git: Too many active changes issue for AWS Lambda project [duplicate] - node.js

Quick question for anyone that is using AWS SAM to deploy their microservices in AWS.
Do you include your .aws-sam files into your repositories? Or do you gitignore this directory and sub directories?

No, you should not revision control the .aws-sam folder(s). Add them to .gitignore.
These folders contain intermediate and output files and will, for example, include Python packages, Node modules and other undesirables. None of these should be committed.

You don't need to include the .aws-sam directory in your repository.
The content of this directory are the artifacts outputted from your sam build command, and can always be recreated.

Related

Uploading a reactjs code in github, without the node_modules folder

I want to upload a react app in github. But, I dont want to HOST IT. I only want to keep the codes there. But while uploading, I had problem with uploading the node_modules folder. I searched other repo, and even there node_modules folder wasn't present. Still their code could be used by running a command called npm install or something similar to that.
What are the steps to upload My ReactJS Code without uploading the node_modules. But in such a way, by which anyone can install all the node modules by npm install or something similar to that?
To tell git to exclude something in your project, you use a .gitignore file. In the .gitignore file, you can add patterns to files or folders and git will not track any of those files.
Here is a template for Node projects given by GitHub. It excludes the node_modules folder. Put it in your project root and remember to rename it to just .gitignore (note the period in front).

packages on a build machine without permanent access to internet

I am in the process of migrating a machine from an older Linux version to a newer one. We have some node projects that seem to be more difficult to transplant to the newly desired setup.
On the old machine the build script from package.json could be run without problems because node_modules is tracked by the source control.
We don't want to use that method anymore since it is not very scalable as we want to make sure we can easily upgrade all the packages for all the users at once without the hassle of putting hundreds of subfolders (from node_modules) together with various resources.
Did you encounter such issues and, if so, how did you manage it?
Can we use a global node_modules somehow to avoid multiple node_modules for each project?
Thank you!
Can we use a global node_modules somehow to avoid multiple node_modules for each project?
There are (at least) three possibilities. Here they are in the order that I would recommend using them:
If Node.js does not find a package in the application's/module's own node_modules directory, it will check in the parent directory (../node_modules) and then that directory's parent directory (../../node_modules) etc. So if all your projects have a shared parent directory, you can put the dependencies in a node_modules directory. See "Loading from node_modules folders" in the Node.js documentation.
A second option is to set the NODE_PATH environment variable to the directory where you would like your projects to search for modules not found elsewhere. See "Loading from the global folders" in the Node.js documentation.
Lastly, it's legacy behavior, but Node.js will also search in three other locations before giving up, so you can use one of those as well: $HOME/.node_modules, $HOME/.node_libraries, and $PREFIX/lib/node. See (again) "Loading from the global folders" for more information.
All that said, please note that the docs also correctly say "It is strongly encouraged to place dependencies in the local node_modules folder. These will be loaded faster, and more reliably."
If you must do this, I would use the first option above and place the node_modules folder as far down in the directory hierarchy as you can.

Should .gitignore also be added and commited to git?

.gitignore is used for ignoring the files which are not expected to be commited to git. It locates in the root directory of the project. So this file should also be added and commited as other files or?
Yes, it's a good practice to commit it, to avoid people in your team to commits temporary files, builds, and other stuffs that aren't project specific.
But if you want to have a modified one locally with a private or testing configuration, you can but if you want to apply changes you have to add it with git add .gitignore.
Documentation: https://git-scm.com/docs/gitignore

Deploy angular2 application

I developed an application in angular2 and now I need to deploy it.
Currently I have a wwww root folder containing:
html files
js files (generated from typescript)
css files (generated from scss)
/node_modules/ folders
/bower_componenets/ folder
The last two folders (node_modules & bower_components) are very heavy (300 mb and thousands of files) and it is very frustrating copy them using FTP.
Is there a way to keep only the needed files?
Thanks a lot
You can use gulp for creating bundle from the libraries into single file ex. vendor.js. Also deploying via ftp is very primitive. You should put your app on GitHub or Bitbucket and then log in to the server and pull your repository there and because you don't put the libraries folders into your git repository you will install the libraries on the server. If you want to go more advance you can use tool like Jenkins combined with gulp task for building your application. Jenkins will build your application automatically and deploy to your server on every push on your git repository
The following question could help you if you want to use Gulp:
How do I actually deploy an Angular 2 + Typescript + systemjs app?
Note that some answers are for beta versions and packaging changed for RC versions.
Angular-cli could also help you to build your application within the following command:
ng build -prod
Moreover using tree shaking could be interesting to minimize the weight of JavaScript files. See this article for more details:
http://blog.mgechev.com/2016/06/26/tree-shaking-angular2-production-build-rollup-javascript/

file organization in node.js project

When creating a node.js project (express based if it matters),
what is the recommended way to store the different files building up the project?
More specifically, dependent external models (being declared as dependencies in package.json) are downloaded to ./node_modules, so where should I place my "locally" created modules ?
Thanks
See nodejs-express-mongoose-demo. It has the perfect file structure.
the standard is to use a local lib directory.
see the node.js libraries on git, there are a million examples.
Cradle Git
Node2XML Git
Express Source on Git

Resources