镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Getting error in open #8561

Description

@Mugesh-Rajaram

MyCode
var http = require('http'),
open = require('open'),
server;
server = http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
});
server.listen(1337, '127.0.0.1',function(){
console.log('Launching the browser!');
open('http://127.0.0.1:1337');
});

CommandPromptError

C:\Users\is5063\Desktop>npm instal open -g
open@0.0.5 C:\Users\is5063\AppData\Roaming\npm\node_modules\open

C:\Users\is5063\Desktop>node server.js
module.js:327
throw err;
^

Error: Cannot find module 'open'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object. (C:\Users\is5063\Desktop\server.js:2:11)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)

Activity

  1. ericmdantas commented on Sep 16, 2016

    @ericmdantas

    That's because you're installing open with the global flag (-g). Run the npm install as npm i --save open and it should work.

  2. Mugesh-Rajaram commented on Sep 16, 2016

    @Mugesh-Rajaram
    Author

    @ericmdantas
    If i use the command (npm i --save open) and do the installation, in which location npm-module will be created

  3. ericmdantas commented on Sep 16, 2016

    @ericmdantas

    @MugeshBTech the location your terminal path is showing.

    In your case, it should be something like: C:\path\to\your\project.

  4. Mugesh-Rajaram commented on Sep 16, 2016

    @Mugesh-Rajaram
    Author

    @ericmdantas
    Thank you so much for your support.

  5. ericmdantas commented on Sep 16, 2016

    @ericmdantas

    You're welcome 😄

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions