LaVOZs

The World’s Largest Online Community for Developers

'; javascript - Node.Js prompt user input - LavOzs.Com

I'm creating a desktop application that talks to SQL Server for MAC users using Node.JS.

Is it possible in Node.JS to take the input from the user and display the data from SQL server based on user input?

For example, in the code below, can I put an input box onload and allow user to input customercode and display InvoiceNumber and customername.

Also, will I be able to run the below code on MAC?

@Serger B,

I followed the link you suggested and was successfully able to connect to SQL Server. How can I add a user prompt to enter the customerCode for the below code? Also, it would be great is someone could help me running the script from the browser.

var sql = require('mssql'); 

var config = {
user: 'temp',
password: 'test123',
server: 'laptop\\localDB', // You can use 'localhost\\instance' to connect to named instance
database: 'AVTemp01',


}

var connection = new sql.Connection(config, function(err) {
// ... error checks

// Query

var request = new sql.Request(connection); // or: var request = connection.request();
request.query('select top 5 companycode from invoiceheader', function(err, recordset) {
    // ... error checks

    console.dir(recordset);
});

// Stored Procedure

var request = new sql.Request(connection);
request.input('input_parameter', sql.Int, 10);
request.output('output_parameter', sql.VarChar(50));
request.execute('procedure_name', function(err, recordsets, returnValue) {
    // ... error checks

    console.dir(recordsets);
});

});

You should try this module to access the SQL server: https://www.npmjs.org/package/mssql We use it successfully in our projects. The quick example on the project homepage just shows it all.

And I don't see anything preventing you to do it on Mac.

Related
Disable/enable an input with jQuery?
How do I debug Node.js applications?
Writing files in Node.js
How do I pass command line arguments to a Node.js program?
Check synchronously if file/directory exists in Node.js
Read environment variables in Node.js
How to decide when to use Node.js?
How to exit in Node.js
What is the purpose of Node.js module.exports and how do you use it?