How to open/run old angular Project in local host - javascript

I'm trying to run old project on the team Drive, but I'm not sure what node version I will use. Is there a way for me to check it in the code or using the terminal?
Another questions:
In the READ ME File, it says here that it use Angular CLI version 6.0.3. -- so do I need to use this version?
Do I need to update the version of my dependency since this one is an old angular project? If yes, how? What command do I need to use?
Is it okay to delete the node_modules and package-lock.json if I use npm install?
This is my whole package.json
{
"name": "sample-tool",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"#agm/core": "^1.0.0-beta.7",
"#angular/animations": "^8.2.0-next.1",
"#angular/common": "^8.2.0-next.1",
"#angular/compiler": "^8.2.0-next.1",
"#angular/core": "^8.1.1",
"#angular/fire": "^5.4.2",
"#angular/forms": "^8.2.0-next.1",
"#angular/platform-browser": "^8.2.0-next.1",
"#angular/platform-browser-dynamic": "^8.2.0-next.1",
"#angular/router": "^8.2.0-next.1",
"#ng-bootstrap/ng-bootstrap": "^4.2.1",
"#swimlane/ngx-charts": "^10.1.0",
"#swimlane/ngx-datatable": "^15.0.2",
"angular-calendar": "^0.25.2",
"angular-datatables": "^6.0.1",
"angular-file-uploader": "^5.0.2",
"angular-notifier": "^4.1.1",
"bootstrap": "^4.4.1",
"bootstrap-icons": "^1.0.0-alpha2",
"c3": "^0.4.23",
"chart.js": "^2.8.0",
"chartist": "^0.11.3",
"core-js": "^2.6.9",
"d3": "^4.8.0",
"datatables.net": "^1.10.19",
"datatables.net-dt": "^1.10.19",
"file-saver": "^2.0.2",
"firebase": "^7.9.3",
"jquery": "^3.4.1",
"lodash": "^4.17.14",
"ng-chartist": "^1.1.1",
"ng-multiselect-dropdown": "^0.2.3",
"ng2-charts": "^1.6.0",
"ng2-completer": "^2.0.8",
"ng2-dragula": "^2.1.1",
"ng2-search-filter": "^0.5.1",
"ng2-slim-loading-bar": "^4.0.0",
"ng2-smart-table": "1.3.5",
"ng2-validation": "^4.2.0",
"ngx-perfect-scrollbar": "6.1.0",
"ngx-quill": "^7.0.2",
"ngx-toastr": "^8.10.2",
"node-sass": "^4.12.0",
"pace-js": "^1.0.2",
"quill": "^1.3.6",
"rxjs": "^6.5.2",
"rxjs-compat": "^6.5.2",
"xlsx": "^0.15.5",
"zone.js": "~0.9.1"
},
"devDependencies": {
"#angular-devkit/build-angular": "^0.803.23",
"#angular/cli": "^8.1.1",
"#angular/compiler-cli": "^8.2.0-next.1",
"#angular/language-service": "^8.2.0-next.1",
"#types/c3": "^0.6.4",
"#types/chartist": "^0.9.46",
"#types/datatables.net": "^1.10.17",
"#types/jasmine": "^2.8.16",
"#types/jasminewd2": "^2.0.6",
"#types/jquery": "^3.3.30",
"#types/node": "~8.9.4",
"codelyzer": "^5.0.1",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "^4.2.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~1.4.2",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "^5.4.1",
"ts-node": "~5.0.1",
"tslint": "~5.9.1",
"typescript": "~3.4.5"
}
}

The project is obviously Angular v8.
So I would say you should do the following steps:
1. Step - Install newest Angular CLI
Angular CLI will recognize if the project itself is using older version of Angular, so no need to limit yourself to the old version of the CLI.
2. Step - Install correct version of the Node.js
For Angular v8, you need Node v10.9.
Note: This Stack Overflow answer have compatibility table, so you can check it once you start upgrading your project.
3. Step - Install dependencies
Install all the dependencies with npm install.
Note: Don't delete package-lock.json and do npm install. package-lock.json keeps the dependency versions and if you delete it and do npm install, it can install newer versions, which can break you project.
4. Step - Run the project
Run the project with npm start.
5. Step (Optional) - Upgrade project to latest version
You can now gradually upgrade your app to newer versions. You can check Angular official guide for upgrading projects.
Note: It is recommended to upgrade only one version at a time. So you should first upgrade to v9, then to v10...
Note: When you upgrade Angular project, you should first upgrade all third-party dependencies to the next version. Otherwise, Angular will throw an error when upgrading, if it finds something incompatible.

Great answer by NeNaD. I just want to add this helpful article that I referred to when I was upgrading my old Angular project, https://www.angularjswiki.com/angular/update-angular-cli-version-ng-update-to-latest-6-7-versions/

Based on your questions:
I'm not sure what node version I will use. Is there a way for me to check it in the code or using the terminal?
You can make use of the node version command as
node -v
or
node --version
it says here that it use Angular CLI version 6.0.3. -- so do I need to use this version?
You could look into upgrade options but since its a old version and you are trying to run it. I would recommend to first use the same version as to see how its running and doesn't cause any abnormalities and then you could upgrade as others suggested
Do I need to update the version of my dependency since this one is an old angular project? If yes, how? What command do I need to use?
I would recommend you do not and so you refer below what is going on.
Version numbers in semantic versioning consist of 3 sets of numbers separated by a ., for example 1.2.3 which represent major.minor.patch respectively. The semantic version documentation explains each of these:
MAJOR version when you make incompatible API changes,
MINOR version when you add functionality in a backwards compatible manner, and
PATCH version when you make backwards compatible bug fixes.
In the package.json, for each dependency you will see a corresponding semver number. Sometimes this is prefixed with a carat ^ or tilde ~.
^1.2.3 — install the latest version of 1.X.X (don’t go past specified major, only a higher minor and patch number).
~1.2.3 — install the latest version of 1.2.X (don’t go past specified major or minor, only a higher patch number).
You can use range operators (e.g. >=) if you need more fine tuned control of the version range.
Is it okay to delete the node_modules and package-lock.json if I use npm install?
You can remove the node_modules as it will be re-created when you re-install using the package.json but keep in mind that if there have been changes made to the node_modules packages then they might be overwritten but this generally doesn't happen but its good to know.
Don't delete your package-lock.json make a copy of it somewhere. Also, deleting the file can affect your version control.
why?
Imagine the project has a dependency, example-package at version ^1.0.0. This is the latest available version at the time of first install and is added to the lock file as 1.0.0. A month later, a new release of example-package comes out 1.1.0. Let’s pretend a new developer joins your team and clones the project repository, and installs the project.
The version in the package.json is ^1.0.0 (meaning the latest 1.X.X), so you would think that the 1.1.0 would be installed on the new developer’s machine, but this is not the case. When the dependency was first added to the project, 1.1.0 did not exist, so the version listed in the lock file is 1.0.0. Therefore 1.0.0 will always be installed, despite there being a newer available version that meets the semantic version specification in the package.json.
If you do not commit the lock file to your repository, or delete the lock file and reinstall your node modules, then version 1.1.0 of example-package will be installed, since it will be treated as if this is the first time installing. New bugs could have been introduced into 1.1.0, or the maybe the package dependencies changed and are incompatible with other dependencies in your project.
This is how deleting the lock file can unintentionally cause dependencies to be upgraded which can break your application.

Related

NPM Installing non root dependencies under node_modules?

The project #superflycss/component-navbox has the following dependencies:
"devDependencies": {
"#superflycss/component-body": "^1.0.1",
"#superflycss/component-display": "^1.0.2",
"#superflycss/component-header": "^2.1.0",
"#superflycss/component-test": "^3.6.14",
"#superflycss/foundation": "^2.0.3",
"#superflycss/superflycss": "^1.0.0",
"#superflycss/utilities-colors": "^3.0.8",
"#superflycss/utilities-effects": "^2.1.0",
"#superflycss/utilities-fonts": "^3.3.7",
"#superflycss/utilities-format": "^1.1.1",
"#superflycss/utilities-layout": "^4.0.4",
"lite-server": "^2.4.0",
"npm-check-updates": "^2.15.0"
},
"dependencies": {
"#superflycss/variables-dimension": "^2.0.0",
"#superflycss/variables-layout": "^2.0.0"
}
So when doing:
git clone git#github.com:superflycss/component-navbox.git
cd component-navbox
npm i
I would expect only the root dependencies to show up in the node_modules folder.
However another dependency variables-colors also shows up in node_modules.
IIUC this should not happen or am I missing something?
One of the problems with this is that the variables-colors version being installed is outdated, however since utilities-colors also depends on this, it uses the older version rather then the newer, and that leads to linting errors, etc.
There was a mismatch between package-lock.json and package.json. I removed the lock file and also node_modules and did npm i and it refreshed with all the dependencies being correct.

Do I need #types/ before every dependency in react native?

I would like to convert my existing react native app to typescript.
The documentation says to uninstall existing dependencies and replace them with something like this:
yarn add --dev #types/jest #types/react #types/react-native #types/react-test-renderer
Do I need to do this with every dependency? What if some dependencies don't have #types/ ?
Here is my package.json:
{
"name": "reactnative",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "react-native start",
"test": "jest"
},
"dependencies": {
"axios": "^0.18.0",
"expo": "^28.0.0",
"faker": "^4.1.0",
"formik": "^0.11.11",
"immutability-helper": "^2.7.1",
"lodash": "^4.17.10",
"native-base": "^2.7.1",
"react": "16.3.1",
"react-native": "0.55.4",
"react-native-actionsheet": "^2.4.2",
"react-native-autogrow-textinput": "^5.1.1",
"react-native-firebase": "^4.2.0",
"react-native-keyboard-input": "^5.2.3",
"react-native-keychain": "^3.0.0-rc.3",
"react-native-material-color": "^1.0.15",
"react-native-parsed-text": "0.0.20",
"react-native-section-list-get-item-layout": "^2.2.3",
"react-native-ui-kitten": "^3.0.1",
"react-native-vector-icons": "^4.6.0",
"react-navigation": "^2.5.5",
"react-redux-firebase": "^2.1.6",
"recompose": "^0.27.1",
"redux-logger": "^3.0.6",
"redux-promise-middleware": "^5.1.1",
"redux-thunk": "^2.3.0",
"yup": "^0.25.1"
},
The documentation says to uninstall existing dependencies and replace them
Actually you have to install both the package, such as react and the related types as #types/react. If react is already installed, you don't have to uninstall and reinstall.
Do I need to do this with every dependency?
As long as you want types for it.
What if some dependencies don't have #types/ ?
Then you either type it on your own, or you type it as any and you don't have the typesafety of Typescript anymore.
No, packages that start with #types/ are TypeScript definitions. They should be installed in addition to the actual packages if these don't already ship with TS definitions (many large/popular libraries do). Your editor and the TypeScript compiler will use the definitions to perform type checking.
#types typings exist for all popular libraries. Some libraries include typings (.d.ts files), no typings are needed for them, the example is axios.
For libraries that don't have typings, a developer can provide own type declarations or use untyped imports, e.g. with require. The example is open issue for react-native-actionsheet.
The documentation says to uninstall existing dependencies
The documentation shouldn't say anything like that. Existing dependencies shouldn't be uninstalled. Only respective #type dependencies should be added.

How to install dependency scripts while installing an npm module [duplicate]

This question already exists:
How to handle script dependencies in angular 2 module published to npm
Closed 5 years ago.
I have published an angular 2 library to npm recently.I have listed all the dependency scripts in the libraries package.json file. when I run npm install my-library all the dependency scripts are not installed.So, my question is how to install the dependency scripts while installing the library.
(This answer is valid for npm5+) In package.json you can specify 3 types of dependencies:
peerDependencies - they are not automatically downloaded in any case ("good to have")
devDependencies - which are downloaded when running npm install in the project itself, packages listed here are needed for development purposes only
dependencies - which are downloaded on every npm install (also when adding your package to someone's project, "must-to-have")
Example:
{
"peerDependencies": {
"#angular/core": ">=2.3.0",
},
"devDependencies": {
"#angular/compiler": "~4.0.0",
"#angular/compiler-cli": "~4.0.0",
"#angular/core": "~4.0.0",
"#angular/platform-server": "~4.0.0",
"#types/node": "^7.0.39",
"core-js": "^2.4.1",
"es6-shim": "^0.35.3",
"rimraf": "^2.5.4",
"rxjs": "^5.4.2",
"tslint": "^4.5.0",
"typescript": "^2.6.1",
"zone.js": "^0.8.16"
},
"dependencies": {
"ngx-store": "^1.2.2"
}
}

how to deploy Angular 2 App to Github Pages?

I was able to publish an app made with Angular Cli tool to Github Pages a few weeks ago, but now when I try to use the command ng github-pages: deploy I get the error: The specified command github-pages:deploy is invalid.. This github thread suggests that the command has been removed recently, and petersgiles recommended following these guidelines instead to publish pages:
1. npm install -g angular-cli-ghpages (doesn't work if its not global)
2.Then in your package.json
"scripts": { "deploy": "ng build -sm -ec -bh /repo name/ & ngh --silent=false",...
3.when you want to deploy npm run deploy
I followed these instructions, but got the error: Failed at the mybiography#0.0.0 deploy script 'ng build -sm -ec -bh /aboutme/ & ngh --silent=false'. My npm and node js are up-to-date, and the error suggests that the problem is inside my package.json file.
My terminal proceeds to render all five chunks of my program, but there's no link to follow to the website. Is there anything i can do to fix this? I completed my website, and just need somewhere to host it. I'm very lost as a beginner, so please point out any obvious mistakes or missing info.
package.json
{
"name": "aboutme",
"version": "0.0.0",
"license": "MIT",
"angular-cli": {},
"scripts": {
"deploy": "ng build -sm -ec -bh /aboutme/ & ngh --silent=false",
"ng": "ng",
"start": "ng serve",
"test": "ng test",
"pree2e": "webdriver-manager update --standalone false --gecko false",
"e2e": "protractor" },
"private": true,
"dependencies": {
"#angular/common": "^2.3.1",
"#angular/compiler": "^2.3.1",
"#angular/core": "^2.3.1",
"#angular/forms": "^2.3.1",
"#angular/http": "^2.3.1",
"#angular/platform-browser": "^2.3.1",
"#angular/platform-browser-dynamic": "^2.3.1",
"#angular/router": "^3.3.1",
"core-js": "^2.4.1",
"rxjs": "^5.0.1",
"ts-helpers": "^1.1.1",
"zone.js": "^0.7.2"
},
"devDependencies": {
"#angular/cli": "^1.0.0-rc.1",
"#angular/compiler-cli": "^2.3.1",
"#types/jasmine": "2.5.38",
"#types/node": "^6.0.42",
"codelyzer": "~2.0.0-beta.1",
"jasmine-core": "2.5.2",
"jasmine-spec-reporter": "2.5.0",
"karma": "1.2.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-remap-istanbul": "^0.2.1",
"protractor": "~4.0.13",
"ts-node": "1.2.1",
"tslint": "^4.3.0",
"typescript": "~2.0.3"
}
}
just wanted to update this old post with an answer that worked for me on this SO post: how to publish to github pages?
There is a new angular cli command to push to gh-pages, the old one no longer works. So you have to install the new command, build the project, then execute the push command.
Try this: (for mac) (does not require any changes to package.json) :
$ npm install -g angular-cli-ghpages
Push your code to a github repo and then run this in terminal: ng build --env=prod --base-href "https://yourgithubusername.github.io/yourprojectname/" here
'yourprojectname' is the name of your github repo, not your local
repo.
If everything works fine, then run : sudo angular-cli-ghpages and enter password.
I suspect ngh --silent=false throws an error. The command for running angular-cli-pages with verbose output at the time of this answer is ngh --no-silent
If you want to update your deploy script, take a look at the angular-cli-pages doc for commands to build and deploy:
> ng build --prod --base-href "https://USERNAME.github.io/REPOSITORY/"
> ngh --no-silent
Here is the simple way without any third party plugin you can deploy angular project to GitHub pages.
STEP 1: Open angular.json of your angular repo.
STEP 2: change dist/your-project-name to docs/
STEP 3: ng build --prod --base-href=https://username.github.io/respository-name/
change username to your GitHub username & respositoryName to repository name of your project.
STEP 4: Commit docs folder to local repo and push to github.
git add .
git commit -m "generated deployables"
git push -u origin master
STEP 5: Open Github repo and open settings
STEP 6: Select master branch /docs folder in github pages.
Congrats !!
Here is VERIFIED step by step detailed guide Article on how to deploy angular project to github pages, if you want more detailed article.

How do I install Angular 2 using NPM?

I'm trying to setup my own local development environment for an Angular 2 app without using the QuickStart seed mentioned in the Angular 2 site or the Angular CLI because they tend to come with extra files that I don't really require.
Now, everything's going fine except that I don't know how to get Angular 2 using NPM. I've tried using npm install angular2 --save but I just found out that angular2 has been deprecated and was a pre-release version. So I guess how do I get the latest Angular 2.0 plugins using NPM, if at all possible at the moment?
at https://angular.io/docs/ts/latest/guide/setup.html, is recommended to use QuickStart seed, here is its package.json, so actually we need to download its dependencies:
"dependencies": {
"#angular/common": "~2.4.0",
"#angular/compiler": "~2.4.0",
"#angular/core": "~2.4.0",
"#angular/forms": "~2.4.0",
"#angular/http": "~2.4.0",
"#angular/platform-browser": "~2.4.0",
"#angular/platform-browser-dynamic": "~2.4.0",
"#angular/router": "~3.4.0",
"angular-in-memory-web-api": "~0.2.4",
"systemjs": "0.19.40",
"core-js": "^2.4.1",
"rxjs": "5.0.1",
"zone.js": "^0.7.4"
}
you could also create your custom package.json, by running npm init, copying these dependencies (or most of them) and than running npm install with your package.json
Angular 4 could be installed in two ways:
Note: Make sure your system already installed node js and npm
Perform the clone-to-launch steps with terminal commands.
Download the QuickStart seed and unzip it into your project folder. Then perform the steps mentioned later with terminal commands.
1. Cloning :
Suppose you want to make a project named helloworld, then run the following commands from your terminal
git clone https://github.com/angular/quickstart.git helloworld
cd helloworld
npm install
npm start
After running last command you could see from your browser like this
2. Downloading :
Download the QuickStart seed and unzip it into your project folder. Then perform the below steps with terminal commands.
cd quickstart
npm install
npm start
For more details go to official site
Paste the below code into a file by creating and naming it as
package.json.
{
"name": "demo-app",
"version": "1.0.0",
"author": "Aravind",
"description": "set up files for the first Demo App",
"scripts": {
"start": "tsc && concurrently \"tsc -w\" \"lite-server\" ",
"tsc": "tsc",
"tsc:w": "tsc -w",
"lint": "tslint ./app/**/*.ts -t verbose",
"lite": "lite-server",
"typings": "typings",
"postinstall": "typings install"
},
"license": "ISC",
"dependencies": {
"#angular/common": "2.0.0",
"#angular/compiler": "2.0.0",
"#angular/core": "2.0.0",
"#angular/forms": "2.0.0",
"#angular/http": "2.0.0",
"#angular/platform-browser": "2.0.0",
"#angular/platform-browser-dynamic": "2.0.0",
"#angular/router": "3.0.0",
"core-js": "^2.4.1",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.12",
"systemjs": "0.19.27",
"zone.js": "^0.6.23",
"bootstrap": "^3.3.6"
},
"devDependencies": {
"concurrently": "^2.2.0",
"lite-server": "^2.2.0",
"tslint": "^3.7.4",
"typescript": "^2.0.2",
"typings": "^1.0.4"
},
"repository": {}
}
navigate to the root folder in Cmd and
npm install
or
npm i
Alternatively if you want to create a new package.json
Navigate to a folder in command prompt
Execute the command
npm init
This will create a new package.json file and copy paste the above code to install angular2 along with few other basic dependencies.
If you are looking for a simple set up. Have a look at this post.
It depend on your build tool, if it is webpack, you need just install angular components, like:
"dependencies": {
"#angular/common": "~4.0.0",
"#angular/compiler": "~4.0.0",
"#angular/core": "~4.0.0",
"#angular/forms": "~4.0.0",
"#angular/http": "~4.0.0",
"#angular/platform-browser": "~4.0.0",
"#angular/platform-browser-dynamic": "~4.0.0",
"#angular/router": "~4.0.0"
}
And all additional vendor modules if it needed in your case.
Install Angular CLI 1.1.3
Uninstall latest version of CLI > npm uninstall –g #angular/cli
Clean the Cache >npm cache clean
Install the Specific version of angular CLI > npm install –g #angular/cli#1.1.3
Open the Node js Command prompt.
Navigate to Project folder location >cd project_name
Install below mentioned packages,
npm i codemirror
npm i ng2-codemirror
npm i ng2-split-pane
npm i ng2-daterange-picker
Run the npm install
Finally do > ng serve
Installing Angular Dependencies
Install a stable version of Node (if not already installed) and verify the installation using node -v
Install TypeScript using command npm install -g typescript
Download and install Angular CLI using command npm install -g #angular/cli
Angular is a component oriented framework. Many components needs to be created to make the whole application. A component is a group of custom elements, HTML elements, ShadowDOM & HTML imports.
Download example from https://angular.io/
Save this code and rename it.
Navigate to the root folder in Cmd.
$ cd myproject
Execute the command
$ npm install
$ npm start

Categories

Resources