Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to start global npm module with harmony flag

I wrote a npm module which can be installed globally dm-npm.

I like to use co in that module.

How can i told the module that it runs with the harmony flag when started globally?

Here is the package.json:

{
  "name": "dm-npm",
  "version": "0.0.3",
  "description": "npm helper",
  "main": "index.js",
  "scripts": {
    "test": "mocha --reporter nyan",
    "start": "node --harmony ./bin/dm-npm"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/divramod/dm-npm.git"
  },
  "keywords": [
    "npm",
    "template"
  ],
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/divramod/dm-npm/issues"
  },
  "homepage": "https://github.com/divramod/dm-npm",
  "devDependencies": {
    "chai": "^2.1.0",
    "mocha": "^2.1.0"
  },
  "dependencies": {
    "co": "^4.4.0",
    "co-prompt": "^1.0.0",
    "colors": "~1.0.3",
    "shelljs": "^0.3.0"
  },
  "bin": {
    "dmnpm": "./bin/dm-npm"
  }
}

i got the following error message when running with a co function:

> $ dmnpm init                                                                                                                         
/usr/local/lib/node_modules/dm-npm/index.js:152
co(function*() {
           ^
SyntaxError: Unexpected token *
    at exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:443:25)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/usr/local/lib/node_modules/dm-npm/bin/dm-npm:3:1)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)

it is caused by

co(function*() {
    var projectName =
        yield prompt('project name: '.blue);
    process.stdin.pause();
});
like image 544
divramod Avatar asked Feb 27 '15 02:02

divramod


People also ask

How use npm global package?

To install a module from npm globally, you'll simply need to use the --global flag when running the install command to have the module install globally, rather than locally (to the current directory). Note: One caveat with global modules is that, by default, npm will install them to a system directory, not a local one.

What does the flag mean when you run npm install?

the -g flag means install the package globally on your system.

What is global npm module?

Global modules are installed in the standard system directory /usr/local/lib/node_modules unlike generic installation which installs the module in the project directory. If you want to know what's the root location of the global module installation, you can do so by typing this command: Shell. npm root -g.


1 Answers

#!/usr/bin/env node --harmony

on the top of script works for me, in your case in /bin/dm-npm

like image 110
Gary Ascuy Avatar answered Oct 14 '22 17:10

Gary Ascuy