Home

Awesome

Learning Node.js

Just one of the things I'm learning. https://github.com/hchiam/learning

tutorial 1:

LearnCode.academy tutorial on YouTube

Terminal/Command-Line commands and localhost:

install node.js
node -v
npm -v
sudo npm install -g express-generator
express exp2016 --hogan -c less
cd exp2016 && npm install
DEBUG=exp2016:* npm start
sudo npm install -g nodemon
nodemon bin/www
nodemon -x 'echo "command to rerun on save";';
nodemon -e html 'echo "this will include watching html files"';

tutorial 2:

http://tutorialzine.com/2012/08/nodejs-drawing-game/

The following steps assume you're using Terminal/Command-Line.

You may need to enter this command to install node.js if you don't already have it installed:

npm install socket.io@0.9.10 node-static

Download the "drawinggame" folder from this repo to get its contents.

Navigate to the "drawinggame" folder so that you're on the same directory level as "app.js".

Enter this command to run the app:

node app.js

Open the "index.html" file in your browser (e.g. Firefox).

To stop running node, hit Ctrl+C in Terminal/Command-Line.

tutorial 3:

https://github.com/hchiam/learning-nodejs/tree/main/fcc

read a local file via console CLI:

// TODO: file name goes here
var fileName = "fileName.js";

var fs = require("fs");
fs.readFile(fileName, "utf8", function (err, data) {
  if (err) return console.log(err);
  // console.log(data);
  processFileText(data);
});

function processFileText(text) {
  // TODO: custom code goes here
  console.log(text);
}

Random notes:

npm -g i # do outside of a repo!!!!! somehow knows it's in a repo and does weird things, or at least in older npm versions

npm cache verify # to clean up unused versions??? also do outside of a repo

Troubleshooting updating node:

https://stackoverflow.com/a/12570971

https://stackoverflow.com/a/26919540

# this may not work:
brew upgrade node
# so just go with the download option:

https://nodejs.org

nvm install v16.13.1; node --version
nvm use v16.13.1
nvm alias default 16

I also saw some weird error and it seemed to go away when I uninstalled and re-installed yarn.

To check what's globally installed with npm: (at depth 0)

npm list -g --depth=0

more JS stuff:

https://github.com/hchiam/learning-js

https://github.com/hchiam/learning-js/tree/main/generate_folder_with_color_theme