繁体   English   中英

如何使节点 js 运行 js 文件并在使用 win10 的 node.js 控制台窗口中创建 js 文件时出现问题

[英]how to make a node js run a js file and issues creating a js file in node.js console window with win10

我是 node js 的初学者,有几个月的 javascript 经验,完成了 codecademy js 和 jquery 入门课程,并在互联网上了解了更多关于 js 的知识,并了解了中级或接近中级的 html 和 css。 我是让 js 和节点 js 一起运行的完整菜鸟。 使用 VS 代码进行文本编辑器。 Node.js 是从他们原来的主页安装的,使用 node.js APP。 名为 global js. 的文件粘贴到 2 个文件夹:与 node.js 和桌面文件夹相同,用于 vs 代码文件(我在 VS 代码中创建的项目或简单文件)。 该死的事情对我来说没有意义,我也不会让这个烂摊子起作用。 更具体地说,那么:

我有两个问题:

首先,安装:npm install javascript bla bla。 很成功,mkdir 和 cd 都成功了。 NUL >introduction.js 表示访问被拒绝。

Alos 我有一个名为 global.js 的文件。 它与 node.js 位于同一个文件夹中 + 此文件的原始版本位于桌面 vs 代码练习的同一文件夹中。 我无法让我的 node.js 打开这个 global.js 文件。

我如何克服这些问题?

我试图以此作为指导方针: 如何在 Windows 上的 Node.js 中运行 hello.js 文件? .

做了上面的以下部分:通过 appwize smth 从运行中将帐户类型更改为 ADMINISTRATOR。 在永久给我自己和管理员状态后从运行中调用 cmd 并且 Windows 将我注销并重新登录。 尝试从命令提示符运行文件,在 cmd 中声明文件的确切路径。 它到达路径,没有显示错误,从那里转到文件。 没有错误,没有发生任何事情......尝试了全局安装,无论那里遇到什么问题,都被它卡住了。

我在这里需要一些帮助! 如果有人可以向我解释什么是错误的以及使用 node.js 的基本概念是什么或者以编程方式启动它的替代方法是什么,那就太好了?

我需要使用 node.js 控制台还是 node.js 应用程序?

代码输入主要。 js:

var http = require("http");
var path= require ("path");
http.createServer(function (request, response) {
// Send the HTTP header 
// HTTP Status: 200 : OK
// Content Type: text/plain
response.writeHead(200, {'Content-Type': 'text/plain'});

// Send the response body as "Hello World"
response.end('Hello World\n');
}).listen(8081);

// Console will print the message
console.log('Server running at http://127.0.0.1:8081/');
console.log (`Rock on World from ${path.basename(__filename)}`);
var http = require("http");

http.createServer(function (request, response) {

// Send the HTTP header 
// HTTP Status: 200 : OK
// Content Type: text/plain
response.writeHead(200, {'Content-Type': 'text/plain'});

// Send the response body as "Hello World"
response.end('Hello World\n');
}).listen(8081);

// Console will print the message
console.log('Server running at http://127.0.0.1:8081/');
  • 不需要使用任何特殊的控制台,在 Windows 上,标准的cmd就足够了。
  • 首先检查节点是否安装正确。 运行node -v并查看它是否打印其版本。
  • 为您的项目创建一个文件夹,并在执行 node 或 npm 之前确保您在其中。 Node.exe 不必在项目文件夹中,只要它在路径中(默认是)
  • 确保您的源文件在该项目文件夹中。 (test.js、introduction.js .. 无论你要运行什么)

暂无
暂无

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

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