Javascript 控制台错误节点配置
我将为android应用程序进行实时聊天,我正在考虑使用NodeJS和websockets,但我以前没有使用过这项技术,而且我在开始使用它时遇到了一些麻烦 我已经从控制台安装了nodejs(我正在使用Archlinux) 当我启动index.js时,控制台(以升华文本形式)会抛出以下错误日志:Javascript 控制台错误节点配置,javascript,json,node.js,websocket,async.js,Javascript,Json,Node.js,Websocket,Async.js,我将为android应用程序进行实时聊天,我正在考虑使用NodeJS和websockets,但我以前没有使用过这项技术,而且我在开始使用它时遇到了一些麻烦 我已经从控制台安装了nodejs(我正在使用Archlinux) 当我启动index.js时,控制台(以升华文本形式)会抛出以下错误日志: [Errno 2] No such file or directory: 'jsc' [cmd: ['jsc', '/srv/http/NodeJsApplication/index.js']] [dir
[Errno 2] No such file or directory: 'jsc'
[cmd: ['jsc', '/srv/http/NodeJsApplication/index.js']]
[dir: /srv/http/NodeJsApplication]
[path: /bin:/usr/bin:/usr/local/bin:/usr/local/sbin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl]
[Finished]
package.json文件如下所示:
{
"name": "nodejsapplication",
"version": "1.0.0",
"description": "NodeJS chat for Android application",
"main": "index.js",
"scripts": {
"start": "index.js",
"test": "make test"
},
"keywords": [
"nodejs",
"npm",
"chat_application"
],
"author": "JProg",
"license": "ISC",
"dependencies": {
"express": "^4.16.3",
"socket.io": "^2.1.0"
}
}
我已经安装了express和NodeJS
我没有使用这项技术的经验
下面是index.js的代码
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res)=>{
res.statusCode=200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hola mundo\n');
});
server.listen(port, hostname, ()=>
console.log('Server running at http://${hostname}:${port}');
);
问题可能出在节点的安装上。 检查是否可以
节点--version
也在您的package.json中的scripts
=>“start”:“node index.js”
。
您是否使用任何IDE从中运行应用程序,如果是,请检查它是否可以找到节点的路径。我所做的是重新安装NodeJS并再次创建项目。 我的代码中也有一些错误,以下是我所做的更改:
"scripts": {
"test": "make test",
"start": "node index.js"
}
还有index.js
var port = 8080;
var hostname = 'localhost';
var express = require('express');
var app = express();
var server = require('http').Server(app);
var io = require('socket.io')(server);
server.listen(port, hostname, 500, function(){
console.log('Executing server on http://localhost:8080');
});
现在它正在运行你能添加
index.js
中的内容吗?我已经添加了它,我忘了它我只使用了升华文本和命令节点——版本:v10.0.0我使用控制台创建了这个项目。试着从命令行运行它(从根目录运行=>npm start
),并检查它是否安装正确。即节点--版本