Skip to content

Instantly share code, notes, and snippets.

@mezcel
Last active May 14, 2020 22:57
Show Gist options
  • Select an option

  • Save mezcel/2cc404f78d2488f02394c81d30047b2d to your computer and use it in GitHub Desktop.

Select an option

Save mezcel/2cc404f78d2488f02394c81d30047b2d to your computer and use it in GitHub Desktop.
Nodejs notes
## win10 line endins
*.bat eol=crlf
*.ps1 eol=crlf
## Linux/Posix line endins
*.sh eol=lf
Makefile eol=lf

nodejs-repl-notes

Links

Electron

quickstart template

# Clone the repository
git clone https://github.com/electron/electron-quick-start
# Go into the repository
cd electron-quick-start
# Install dependencies
npm install
# Run the app
npm start

main.js template

// Modules to control application life and create native browser window
const {
        app, 
        BrowserWindow
    } = require('electron')
const path = require('path')
const url = require('url')

function createWindow () {
  // Create the browser window.
  const mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      preload: path.join(__dirname, 'preload.js')
    }
  })

  // and load the index.html of the app.
  //mainWindow.loadFile('index.html')
  mainWindow.loadURL(url.format({
    pathname: path.join(__dirname, 'view/index.html'),
    protocol: 'file:',
    slashes: true

  }))

  // Open the DevTools.
  // mainWindow.webContents.openDevTools()
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(() => {
  createWindow()
  
  app.on('activate', function () {
    // On macOS it's common to re-create a window in the app when the
    // dock icon is clicked and there are no other windows open.
    if (BrowserWindow.getAllWindows().length === 0) createWindow()
  })
})

// Quit when all windows are closed.
app.on('window-all-closed', function () {
  // On macOS it is common for applications and their menu bar
  // to stay active until the user quits explicitly with Cmd + Q
  if (process.platform !== 'darwin') app.quit()
})

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
console.log("List env vars:", process.argv);
console.log("just the args:", process.argv.slice(2));
var argArr = process.argv.slice(2);
console.log("1st arr:", argArr[0]);
console.log("if dir:", process.env[argArr[0]]);
{
"name": "nodejs-notes",
"version": "1.0.0",
"description": "notes",
"main": "repl-dirs.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://gist.github.com/2cc404f78d2488f02394c81d30047b2d.git"
},
"keywords": [
"notes"
],
"author": "Mezcel",
"license": "ISC",
"bugs": {
"url": "https://gist.github.com/2cc404f78d2488f02394c81d30047b2d"
},
"homepage": "https://gist.github.com/2cc404f78d2488f02394c81d30047b2d"
}
/* ls contents in a dir */
var path = require('path');
var fs = require('fs');
__dirname = path.resolve();
var dir = path.join(__dirname, 'Documents');
files.forEach( function(file) { ;
files.forEach( function(file) { ;
console.log(file);
});
});
// List environment file path vars
console.log( process.env );
// change dir
process.chdir("HOMEPATH");
var dir = path.join(__dirname, 'Documents');
fs.readdir( dir, function(err, files){
if (err) {
return console.log("cant find dir: " + err)
};
files.forEach( function(file) { ;
files.forEach( function(file) { ;
console.log(file);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment