简体   繁体   中英

I get this syntax error when running my server.js trying to connect to my sql db

I wrote this script to connect to my local DB with mssql and node.js.

Here is my "server.js" script:

const sql = require(‘mssql’);

//write the configuration to connect to our database:
var config = {

 user: ‘root’,

 password: ‘’,

 server: ‘localhost’,

 database: ‘testangular’

 };

sql.connect(config, function(err) {

 if (err) { console.log(‘Connect err: ‘ + err); return; }

 isConnected = true;

});

When I run it I get this syntax error: screenshot

I'm kind of new to javascript, so it might be a ridiculous mistake, but your help will be appreciated!!

That is probably because You're using apostrophes. You should not use ' and ' but ' or " .

const sql = require('mssql');

// write the configuration to connect to our database:
var config = {
 user: 'root',
 password: '',
 server: 'localhost',
 database: 'testangular'
};

sql.connect(config, function(err) {
 if (err) { console.log('Connect err: ', err); return; }
 isConnected = true;
});

Tip : I also suggest using semicolon here, in case err is an object. console.log('Connect err:', err);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM