简体   繁体   English

无法安装运行文件javascript nodejs fedora 18 linux

[英]cannot install run file javascript nodejs fedora 18 linux

i have a server with fedora 18. i already try to download nodejs with this command line 我有一台装有fedora 18的服务器。我已经尝试使用此命令行下载nodejs。

wget "https://nodejs.org/dist/v4.2.2/node-v4.2.2-linux-x64.tar.gz"

then i install node-dev like this.. 然后我像这样安装node-dev。

npm install -g node-dev

after that i create a folder and a file package.json : 之后,我创建一个文件夹和一个文件package.json:

{
    "name":"NoChat",
    "version":"0.0.1",
    "description":"Akiong Test Chat",
    "dependencise":{
        "socket.io":"latest",
        "express":"latest"
    },
    "author":"akiong-Ryobest"
}

and this is index.html 这是index.html

<!DOCTYPE html> 
<html> 
<head> 
    <title>Nostra Chat</title> 
    <style type="text/css"> 
        body, div, p { margin: 0; padding: 0; } 
        body { font-family: "Arial"; } 
        form { position: fixed; bottom: 0; width: 100%; margin: 0; padding: 0; } 
        form textarea { width: 100%; height: 50px; padding: 10px; margin: 0; border: 1px solid #bbb; }
        #messages { list-style-type: none; margin: 0; padding: 0; background: #fff; } 
        #messages li { padding: 5px 10px; }         
        #main { 
            width: 85%; 
            margin: 10px; 
        } 
        #side { 
            width: 15%; 
            background: #fff; 
            position: absolute; 
            top: 0; bottom: 75px; right: 0; 
            border: 1px solid #bbb; 
        } 
        #side .header { 
            background: #eee; 
            color: #333; 
            margin: 0; 
            padding: 5px 10px; 
            font-weight: bold; 
            position: relative; 
            border-bottom: 1px solid #bbb; 
        } 
        #side .header p { 
            width: 100%; 
        } 
        #side .header #logout { 
            text-align: right; 
            position: absolute; 
            right: 10px; 
            text-decoration: none; 
            color: #888; 
        } 
        #side .header #logout:hover { 
            color: #333; 
        } 
        #user-list { 
            list-style-type: none; margin: 0; padding: 0; 
            padding: 5px 10px; 
        } 
        #user-list .current-user { font-weight: bold; } 
    </style> 
</head> 

<body> 
    <div id="main"> 
        <ul id="messages"> 
            <!--<li class="my-message">Hi server</li>--> 
            <!--<li>Hello client</li>--> 
        </ul> 
    </div> 

    <div id="side"> 
        <p class="header">Online</p> 
        <ul id="user-list"> 
            <!--<li class="current-user">Fani</li>--> 
        </ul> 
    </div> 

    <form action=""> 
      <textarea name="messageText" autocomplete="off"></textarea> 
    </form>       
</body> 
</html>

this is server.js 这是server.js

var express = require('express'), 
    app = express(), 
    port = 3000 
    ; 

/** 
 * Meng-konfigurasi express untuk meng-look-up file html 
 * dari directory bernama "public" 
 */ 
app.use(express.static(__dirname + '/public')); 

/** 
 * Pada saat browser me-request path "/" 
 * response dengan file bernama "index.html" 
 */ 
app.get('/', function(req, res){
    res.sendfile('index.html'); 
}); 

/* 
 * Meng-konfigurasi express untuk listen pada 
 * port yang telah di tentukan 
 */ 
app.listen(port, function(){ 
    console.log('listening on *:' + port); 
});

then i try to run server.js with this command. 然后我尝试使用此命令运行server.js。

node-dev server.js

but i get this error.. 但我得到这个错误。

[root@server NoChat]# node-dev server.js
Error: Cannot find module 'express'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/root/NoChat/server.js:1:77)
    at Module._compile (module.js:456:26)
    at Module._extensions..js (module.js:474:10)
    at Object.nodeDevHook [as .js] (/usr/lib/node_modules/node-dev/lib/hook.js:43:7)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
[ERROR] 22:21:45 Error

what wrong with my step? 我的步骤怎么了?

or any suggestion for me? 或对我有什么建议? i am trying to create a chatting with websocket... 我正在尝试与websocket聊天...

The error is quite clear: 错误很明显:

Error: Cannot find module 'express'

You do not have the module express installed. 您没有安装express模块。 To install it, run npm install express in the command line (while in the same folder as the server.js file). 要安装它, npm install express在命令行中(与server.js文件位于同一文件夹中)运行npm install express

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM