DEV Community

lund8888
lund8888

Posted on

exe closes immediately

Hello, this is my first time with node.js
I followed your example and I could create an exe for windows, perfect. Let's say that we wish to add a part of "Hello world" in the main with a timeout , something like this :

var http = require('http');

var server= http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(8124);

console.log('Server running at http://127.0.0.1:8124/');

server.setTimeout(100000);

I can compile it and create the exe. However, when I open the exe it closes directly and I cannot see what I expect as an output, the console looks like crushing and closes immediately. First world problems I guess...

Can you help?

Top comments (5)

Collapse
 
lund8888 profile image
lund8888 • Edited

the procedure described, should create an exe that is opened any how anywhere, correct? I am using windows. So I double click on the exe, it immediately closes and I don't see anything. So I followed your advice and I type it and I just type prettyprint.exe at the path where my project is and I see a throw err :

Server running at 127.0.0.1:8124/
internal/fs/utils.js:453
throw err;
^
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be one of type string, Buffer, or URL. Received type undefined
at Object.openSync (fs.js:435:3)
at Object.fs.openSync (pkg/prelude/bootstrap.js:491:32)
at Object.readFileSync (fs.js:343:35)
at Object.fs.readFileSync (pkg/prelude/bootstrap.js:687:36)
at module.exports (C:\snapshot\example_exec\main.js:5:19)
at Object. (C:\snapshot\example_exec\bin.js:8:5)
at Module._compile (pkg/prelude/bootstrap.js:1324:22)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:651:32)
at tryModuleLoad (internal/modules/cjs/loader.js:591:12)

Collapse
 
katnel20 profile image
Katie Nelson

Looks like you missed a path parameter somewhere.

Collapse
 
lund8888 profile image
lund8888 • Edited

Hi, thank you for your message. I m running the file from this path
C:\Users\myname\Documents\Node_apps\internet\example_exec> prettyprint.exe

this is my main.js , I simply pasted the code:

module.exports = filePath => JSON.stringify(JSON.parse(require('fs').readFileSync(filePath).toString()), false, 3)
var http = require('http');
var server= http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(8124);

console.log('Server running at 127.0.0.1:8124/');
server.setTimeout(100000);

Unless you mean that the path should be specified like this in the main.js,
module.exports = function(C:\Users\myname\Documents\Node_apps\internet\example_exec) {
I thought it is generic.

This is the bin.js:

const prettyprint = require('.') /* the current working directory so that means main.js because of package.json /
let theFile = process.argv[2] /
what the user enters as first argument */
console.log(
prettyprint(theFile)
)
console.log(require('.')(process.argv[2]))

This is the package.json:

{
"name": "prettyprint",
"version": "0.0.1",
"description": "Pretty print a JSON file.",
"main": "main.js",
"bin": "bin.js",
"author": "anybody",
"license": "MIT"
}

There is no mistake at the path, the path of the terminal is correct

Do you see the attachment of the path I uploaded?
All the files are in : C:\Users\myname\Documents\Node_apps\internet\example_exec
The folder contains:
bin.js
main.js
package.json
prettyprint.exe

Collapse
 
katnel20 profile image
Katie Nelson

When you say “open the exe” how are you doing this? What about first opening a terminal window and typing out the full path to the exe file? You should see any output from the execution.

Collapse
 
mandaputtra profile image
Manda Putra

what is exe though? THere are no executable in node.js, not like JavaFx or somewhat related