How to exit properly from node.js

The following will read and import many CSV files from disk into MongoDB but NodeJS won't exit after importing all the files if it doesn't go through the resizePhoto() function (Which contains a process.exit after resizing the images). How can I have it to close properly after importing all files without interrupting? If I add a process.exit .on end it will exit after importing the fir

如何从node.js正确退出

下面将读取和导入许多CSV文件从磁盘到MongoDB,但如果没有通过resizePhoto()函数(它包含调整图像大小后的process.exit),导入所有文件后,NodeJS不会退出。 如何在不中断导入所有文件后正确关闭它? 如果我添加一个process.exit .on,它将在导入第一个文件后退出。 var importData = function(fileName) { // Get file from disk. var filePath = path.join(folder, fileName); // Read and import the CSV

How to exit callback loop in javascript

I have a simple codesnippet in a file test.js: [1, 2, 3, 4].forEach(function(e) { console.log(e); }); whenever I run node test.js in terminal I get the output 1 2 3 4 | But the program never really exits. I am required to end it manually. Seems quite trivial but I am unable to figure out a proper way to exit the scrip in the terminal. UPDATE 1: var mongoose = require('mongoose'); va

如何退出JavaScript中的回调循环

我在test.js文件中有一个简单的codesnippet: [1, 2, 3, 4].forEach(function(e) { console.log(e); }); 每当我在终端运行node test.js ,我都会得到输出 1 2 3 4 | 但该计划从未真正退出。 我需要手动结束它。 看起来很琐碎,但我无法找出一个合适的方式在终端中退出scrip。 更新1: var mongoose = require('mongoose'); var User = require('../models/users/user'); var UserProfile = require('../models/user

NodeJS close previous server port before creating new server

Here, I am doing some development and testing so each time I change something I've to exit server and do changes and start new server. For first time when I run command node server.js file it works like a charm but when I exit it and do some changes and start again it gives me this error in console : throw er; // Unhandled 'error' event I searched a bit about it and I found that this err

在创建新服务器之前,NodeJS关闭以前的服务器端口

在这里,我正在做一些开发和测试,所以每次我改变一些东西以退出服务器并进行更改并启动新的服务器。 我第一次运行命令node server.js文件时,它的作用就像一个魅力,但当我退出它并做一些更改并重新启动时,它在控制台中给我提供了这个错误: throw er; // Unhandled 'error' event 我搜索了一下,发现这个错误发生在这个端口已经被使用的时候,当我改变了端口名称,然后启动它就可以正常工作。 var express = require("ex

execute node.js without using command prompt(either winform or javascript)?

I am Totally new to Node.js, i have a node app running, but now i need to execute the node.js program without using command prompt atall. It maybe through winform app(using vb.net) or using javascript. Can somebody help me out on this? Cheers Jeev I blogged about how to create a standalone EXE for NodeJS apps here: http://www.alexjamesbrown.com/blog/development/create-a-standalone-exe-to

不使用命令提示符(winform或javascript)执行node.js?

我完全不熟悉Node.js,我有一个节点应用程序正在运行,但现在我需要执行node.js程序而不使用命令提示符atall。 它可能通过winform应用程序(使用vb.net)或使用JavaScript。 有人能帮我解决这个问题吗? 干杯杰夫 我在这里博客了解如何为NodeJS应用程序创建独立的EXE: http://www.alexjamesbrown.com/blog/development/create-a-standalone-exe-to-run-a-node-js-application 你不是真的通过一个单独的应用程序运行

what prevents node.js to exit process?

Is there any way to debug or determine what prevents node.js script to exit? All my code run is finished, I removed all event listeners, but process is still active. You can use process.exit(<code>) to leave the program and check what they call "event loop" too source : http://nodejs.org/api/process.html#process_process_exit_code and : http://nodejs.org/api/repl.html

什么阻止node.js退出进程?

有什么方法可以调试或确定什么阻止node.js脚本退出? 我所有的代码运行完成后,我删除了所有事件监听器,但进程仍处于活动状态。 你可以使用process.exit(<code>)离开程序并检查他们称之为“事件循环” 来源:http://nodejs.org/api/process.html#process_process_exit_code 和:http://nodejs.org/api/repl.html

What's the purpose of the process exit event in node js?

I'm having a look at the docs of node.js: process event exit. Emitted when the process is about to exit. There is no way to prevent the exiting of the event loop at this point, and once all exit listeners have finished running the process will exit. Therefore you must only perform synchronous operations in this handler. This is a good hook to perform checks on the module's state (lik

节点js中的进程退出事件的目的是什么?

我正在查看node.js的文档:process event exit。 当进程即将退出时发出。 在这一点上没有办法阻止事件循环的退出,并且一旦所有退出监听器完成运行,该进程将退出。 因此,您只能在此处理程序中执行同步操作。 这是对模块状态执行检查的好钩子(比如单元测试)。 该回调函数采用一个参数,该进程正在退出的代码。 基本用法如下所示: process.on('exit', function(code) { console.log('About to exit with code:',

How can I use Nodejs with Windows 7?

I'm about to became insane looking for it, most of the examples shows only how to run it on linux terminal and just the communication with the server. Can someone PLEASE explain to me how I can use NodeJs (make it run and load whatever is needed) in Windows 7? and PLEASE, how can I integrate it with my HTML5 code? I really appreciate your answers From: http://dailyjs.com/2012/05/03/win

我如何在Windows 7上使用Nodejs?

我即将变得疯狂寻找它,大多数例子只展示了如何在linux终端上运行它,以及如何在服务器上进行通信。 有人可以向我解释我如何在Windows 7中使用NodeJs(使其运行并加载所需的任何内容)? 请问,我如何将它与我的HTML5代码整合? 我非常感谢你的回答 来自:http://dailyjs.com/2012/05/03/windows-and-node-1/ 要下载节点,请转至nodejs.org,单击“下载”,然后单击“Windows Installer”。 这会给你一个Windows安装程序(

Node.js Generate html

I have created a JavaScript program which generates a list of data. Example output below: output one output two output three ... I would like to be able to generate a HTML file which can be saved to disk and opened with a browser. Below is a sample of the HTML I would like to generate. <html> <head> </head> <body> <table id="history_table">

Node.js生成html

我创建了一个生成数据列表的JavaScript程序。 下面的示例输出: output one output two output three ... 我希望能够生成一个可以保存到磁盘并用浏览器打开的HTML文件。 以下是我想要生成的HTML样本。 <html> <head> </head> <body> <table id="history_table"> <tr> <td>header 1</td> <td>hea

How is the 'use strict' statement interpreted in Node.js?

This question already has an answer here: What does “use strict” do in JavaScript, and what is the reasoning behind it? 26 answers "use strict"; Basically it enables the strict mode. Strict Mode is a feature that allows you to place a program, or a function, in a "strict" operating context. In strict operating context, the method form binds this to the objects as bef

在Node.js中如何解释'use strict'语句?

这个问题在这里已经有了答案: JavaScript中使用“严格使用”是什么,它背后的原因是什么? 26个答案 "use strict"; 基本上它启用了严格的模式。 严格模式是一项功能,可让您在“严格”操作环境中放置程序或功能。 在严格的操作环境中,方法形式像以前一样将其绑定到对象。 函数形式将其绑定到未定义的,而不是全局集合对象。 根据你的评论,你说的是一些不同之处。 但这是你的假设。 Node.js代码只是你的J

How to develop Desktop Apps using HTML/CSS/JavaScript?

First, I'm not interested in doing this professionally. I am a web developer, a coworker of mine recently left for Spotify and said he will be working mostly in JavaScript for the Spotify Desktop app. He said it uses "Chrome frame" and everything inside is done like a web app (HTML/JS/CSS). As a web developer who never built anything for Desktop, this is great news. If I can us

如何使用HTML / CSS / JavaScript开发桌面应用程序?

首先,我不想专业做这件事。 我是一名Web开发人员,最近离开了Spotify的同事,并表示他将主要为Spotify桌面应用程序开发JavaScript。 他说,它使用“Chrome框架”,里面的一切都像一个网络应用程序(HTML / JS / CSS)完成。 作为一个从未为桌面创建任何东西的Web开发人员,这是一个好消息。 如果我可以使用我已经知道的技术并在某种“框架”中实现它们,并且仍然能够构建一个Windows或更好的跨平台应用程序。 我知道我没有提