Showing posts with label Node. Show all posts
Showing posts with label Node. Show all posts

Monday, 26 September 2022

ubuntu 22.04 install latest node JS and npm , and how to remove them, and how to install ng (angular CLI)

 Remove nodeJS and npm :

https://stackoverflow.com/questions/32426601/how-can-i-completely-uninstall-nodejs-npm-and-node-in-ubuntu

sudo apt-get remove nodejs
sudo apt-get remove npm

Install latest npm : (recommneded using nvm - node version management)

https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-22-04

#Install node using nvm will also autmotically install npm
  1. curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh

Take a look and make sure you are comfortable with the changes it is making. When you are satisfied, run the command again with | bash appended at the end. The URL you use will change depending on the latest version of nvm, but as of right now, the script can be downloaded and executed by typing:

  1. curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

This will install the nvm script to your user account. To use it, you must first source your .bashrc file:

  1. source ~/.bashrc
// Install version v16.4.0
  1. nvm install v16.14.0



# Install angular CLI
https://stackoverflow.com/questions/37227794/ng-command-not-found-while-creating-new-project-using-angular-cli

must install by npm or else ng command will not be found
# install angular cli according to your package.json version
npm install -g @angular/cli

Install a specific version
https://stackoverflow.com/questions/43344600/how-to-install-a-specific-version-of-angular-with-angular-cli
npm uninstall -g angular-cli
npm cache clean
npm install -g @angular/cli@12.2.13

Wednesday, 25 March 2020

Node module export/import && JS export/import with default and named

Bump
The module.exports or exports is a special object which is included in every JS file in the Node.js application by default. module is a variable that represents current module and exports is an object that will be exposed as a module. So, whatever you assign to module.exports or exports, will be exposed as a module.
var msg = require('./Messages.js');

console.log(msg);

JS export
The export statement is used when creating JavaScript modules to export functions, objects, or primitive values from the module so they can be used by other programs with the import statement.

There are two types of exports:
  1. Named Exports (Zero or more exports per module)
  2. Default Exports (One per module)
// file test.js
let k; export default k = 12;
// some other file
import m from './test'; // note that we have the freedom to use import m instead of import k, because k was default export
console.log(m);        // will log 12


// In childModule1.js
let myFunction = ...; // assign something useful to myFunction
let myVariable = ...; // assign something useful to myVariable
export {myFunction, myVariable};
// In childModule2.js
let myClass = ...; // assign something useful to myClass
export myClass;
// In parentModule.js
// Only aggregating the exports from childModule1 and childModule2
// to re-export them
export { myFunction, myVariable } from 'childModule1.js';
export { myClass } from 'childModule2.js';
// In top-level module
// We can consume the exports from a single module since parentModule
// "collected"/"bundled" them in a single source
import { myFunction, myVariable, myClass } from 'parentModule.js'
https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/export







https://www.tutorialsteacher.com/nodejs/nodejs-module-exports