2016年11月30日 星期三

win10上以emacs開發node.js的安裝、設定


  1. 執行 emacs
  2. 以M-! path執行系統路徑檢視,看看目前環境設定中是否已有舊版node.js,記錄其位置,在安裝新版時可以考慮安裝在同一位置以覆寫之
  3. 到 https://nodejs.org/en/ 下載最新版(我抓的是 node-v6.9.1-x64.msi )並安裝
  4. 接下來試試新模組的安裝,以此模組為例 https://www.npmjs.com/package/google-scholar
  5. 新建並進入測試目錄,以放置範例程式及所用到的模組
  6. 在命令列視窗執行 npm install google-scholar --save
  7. 範例程式如下,C-x C-f新建此檔案,輸入完整目錄、檔案名稱(記得副檔名為js),複製貼上以下內容
'use strict'
let scholar = require('google-scholar')
scholar.search('CRISPR')
  .then(resultsObj => {
    console.log(resultsObj)
  })

  1. M-! node 完整目錄、檔案名稱(記得副檔名為js),結果會出現在另一視窗
  2. 一些 emacs 上執行命令的方式列舉如下,自己看者辦囉
    M-! cmd RET
    Run the shell command line cmd and display the output (shell-command).
    M-| cmd RET
    Run the shell command line cmd with region contents as input; optionally replace the region with the output (shell-command-on-region).
    M-x shell
    Run a subshell with input and output through an Emacs buffer. You can then give commands interactively.
    M-x term
    Run a subshell with input and output through an Emacs buffer. You can then give commands interactively. Full terminal emulation is available.
    M-x eshell
    Start the Emacs shell.