简体   繁体   English

node index.js 命令同时启动和结束服务器

[英]node index.js command start and end server in the same time

I did install WSL2 and ubuntu 22.04 distribution on windows 11. I configured envoirment, installed nvm, node v.16.17.1, next in my folder did npm init, installed express, created index.js file within simple structure:我确实在 windows 11 上安装了 WSL2 和 ubuntu 22.04 发行版。我配置了环境,安装了 nvm,节点 v.16.17.1,接下来在我的文件夹中进行了 npm 初始化,安装了 express,在简单结构中创建了 index.js 文件:

const express = require('express')
const app = express()
const port = 3000

app.get('/', (req, res) => {
  res.send('Hello World!')
})

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`)
})

When i tap node index.js nothing happen.当我点击node index.js时,什么也没有发生。 image图片

In my second computer with ubuntu 20.04 distribution everything work fine.在我使用 ubuntu 20.04 发行版的第二台计算机中,一切正常。 Does anyone know what to do?有谁知道该怎么办?

How about doing debugging by referring to https://expressjs.com/en/guide/debugging.html ?参考https://expressjs.com/en/guide/debugging.html调试一下如何?

like this,像这样,

DEBUG=express:* node index.js

If no other problem is found, it would be good to use the --inspect options.如果没有发现其他问题,最好使用--inspect选项。 https://nodejs.org/en/docs/guides/debugging-geting-started/ https://nodejs.org/en/docs/guides/debugging-geting-started/

Problem resolve.问题解决。 File need to be SAVE before calling from terminal....在从终端调用之前需要保存文件....

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

相关问题 Node.js-启动命令使节点崩溃,但是index.js运行正常 - Node.js - start command crashing node, but index.js running fine 命令 vite start 是否比 node./index.js 有一些优势 - Does the command vite start have some advantages over node ./index.js index.js 命令 - Command for index.js 如何让 $node index.js 在我的命令行中运行 index.js? - How can I get $node index.js to run index.js in my command line? 节点-不能在同一文件夹中要求('./index.js') - Node - Cannot require('./index.js') in the same folder node.js命令行程序(使用Commander节点模块)在执行时打开index.js - node.js command line programs(using commander node-module) opens index.js on execution MySQL 数据库连接的 Node.JS 错误:使用命令“NODE INDEX.JS”运行服务器时,终端给我两个错误 - Node.JS Error with MySQL Database Connection: Terminal is giving me two errors when running my server using the command "NODE INDEX.JS" 503将node.js部署从server.js切换到index.js(初学者)时出错 - 503 Error when switching node.js deployment from server.js to index.js (beginner) 如何仅使用 index.js 和 package.json 和节点模块文件启动 nodejs 项目 - How to start a nodejs project with only index.js and package.json and node modules files 将数据返回给index.js节点 - returning data to index.js node express
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM