在CentOS上测试Node.js应用程序可以通过以下几种方法进行:
debugger; 语句。node inspect your_script.js。chrome://inspect,点击“Configure”并添加你的Node.js进程。F5 或点击左侧活动栏中的调试图标,然后点击“创建一个launch.json文件”。launch.json 文件中,配置调试设置,例如:{ "version": "0.2.0", "configurations": [ { "type": "node", "request": "launch", "name": "Launch Program", "program": "${workspaceFolder}/app.js" } ] } F5),Visual Studio Code将启动你的Node.js应用程序并提供调试控制。npm install -g nodemon。nodemon --inspect app.js。你可以创建一个简单的Node.js脚本来测试安装是否成功。例如,创建一个名为 app.js 的文件,内容如下:
const http = require('http'); const server = http.createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Hello World '); }); server.listen(3000, () => { console.log('Server running at http://localhost:3000/'); }); 然后在终端中运行以下命令来启动服务器:
node app.js 打开浏览器并访问 http://localhost:3000,如果看到“Hello World”的消息,则说明Node.js已成功运行。
以上就是在CentOS上测试Node.js应用程序的一些方法,你可以根据自己的需求选择合适的调试方式。