Skip to content

Instantly share code, notes, and snippets.

@yogain123
Last active May 2, 2022 13:20
Show Gist options
  • Save yogain123/c4516979c00dae9b01bbdfd1ecb3ba2c to your computer and use it in GitHub Desktop.
Save yogain123/c4516979c00dae9b01bbdfd1ecb3ba2c to your computer and use it in GitHub Desktop.
npm+webpack
@yogain123
Copy link
Author

Versioning

"lodash":"^4.12.11"
it means leave the major version , but get lastest stable minor and patch version when doing npm install

"lodash":"~4.12.11"
it means leave the major and minor version , but get lastest stable patch version when doing npm install

"lodash":"*"
get latest stable version of lodash

@yogain123
Copy link
Author

yogain123 commented May 26, 2019

Command

npm install lodash --save
npm update lodash --save
npm uninstall lodash --save
npm install
npm update
npm install nodemon -g
npm update -g // update all global dependencies
npm list
npm cache clean --force

To remove package which are present in local but not present in package.json
npm prune

@yogain123
Copy link
Author

yogain123 commented May 26, 2019

Scripts

"scripts":{
  "start":"node index.js"
  "hola":"nodemon"
}

npm start
npm run hola // running custom script

@yogain123
Copy link
Author

yogain123 commented Jul 19, 2019

Running Backend and Frontend in Same Server (Express)

Screen Shot 1941-04-29 at 3 19 43 AM



Screen Shot 1941-04-29 at 3 23 47 AM

Usually scripts run the root of package.json , to add prefix , to say run it on some other dir , so here running inside client
`"client":"npm run start --prefix client"

Running both FE and BE together with one command , write a script
"dev":"concurrently \"npm run server\" \"npm run client\""

@yogain123
Copy link
Author

yogain123 commented Jul 19, 2019

deploying

For NodeJS

Screen Shot 1941-04-29 at 3 54 39 AM



For React

Screen Shot 1941-04-29 at 3 56 21 AM

@yogain123
Copy link
Author

prettier

npm install prettier -g

prettier --write *.js
prettier --write *.ts

prettier --write src/**/*.ts

@yogain123
Copy link
Author

get list of global npm package

npm list -g --depth 0

@yogain123
Copy link
Author

  • npm install -g something
  • npm install something --save
  • npm start
  • npm start targetFile
  • npm run build
  • npm run build --prod
  • yarn install
  • yarn add lodash --save

yarn doesn't install global dependecies

@yogain123
Copy link
Author

NVM

Download NVM from github

  • nvm install 8.9.9
  • nvm list
  • nvm use 8.9.9
  • nvm alias default 8.9.4

@yogain123
Copy link
Author

npx

node package executable

execute local installed things without writing down it in script
, if json-server is installed locally , then you can run

npx json-server -p 1234 -w db.json

@yogain123
Copy link
Author

Server Side Templating VS Single Page App

Screen Shot 1941-04-26 at 10 33 14 PM



Screen Shot 1941-04-26 at 10 33 27 PM



Screen Shot 1941-04-26 at 10 33 34 PM

@yogain123
Copy link
Author

Core Purpose of Javascript

Screen Shot 1941-04-26 at 10 45 56 PM

@yogain123
Copy link
Author

extra

vendor.js

Screen Shot 1941-04-27 at 12 11 40 AM



Screen Shot 1941-04-27 at 12 15 20 AM



WebPack bundles all the file and babel convert ES6 from that bundles files to old version which all browser can understand



local dependencies ==> okay
global dependencies ==> okay

but if you want to run global dependencies installed locally, then you need to write script and run, otherwise it won't work
example::

npm install json-server -g // now running json-server from anywhere will work properly
BUT
npm install json-server --save // now running json-server will not work in project folder . thats why put it in script

"scripts":{
  "executeMe":"json-server"
}

then ==> npm run executeMe

@yogain123
Copy link
Author

yogain123 commented Apr 25, 2022

check module info

npm info <module-name>
npm info lodash

@yogain123
Copy link
Author

yogain123 commented Apr 26, 2022

more npm command

pnpm -> check it for monorepo
npm link
npm pack
npm ls <package-name> --> print to stdout all the versions of a package that is installed, including their dependencies in a tree-structure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment