Table of Contents |
---|
...
...
https://docs.npmjs.com/cli/v6/commands/npm-uninstall/
to remove the NPM global package
...
$ npm install config
$ mkdir config
$ vi config/default.json
{
// Customer module configs
"Customer": {
"dbConfig": {
"host": "localhost",
"port": 5984,
"dbName": "customers"
},
"credit": {
"initialLimit": 100,
// Set low for development
"initialDays": 1
}
}
}
Edit config overrides for production deployment:
$ vi config/production.json
{
"Customer": {
"dbConfig": {
"host": "prod-db-server"
},
"credit": {
"initialDays": 30
}
}
}
Use configs in your code:
const config = require('config');
//...
const dbConfig = config.get('Customer.dbConfig');
db.connect(dbConfig, ...);
if (config.has('optionalFeature.detail')) {
const detail = config.get('optionalFeature.detail');
//...
}
config.get()
will throw an exception for undefined keys to help catch typos and missing values. Use config.has()
to test if a configuration value is defined.
Start your app server:
$ export NODE_ENV=production
$ node my-app.js
...
https://stackabuse.com/reading-and-writing-csv-files-in-nodejs-with-node-csv/
install the entire node-csv
suite:
npm install node-csv
Read csv file with fileStream and Callback api
csv-parse
package provides multiple approaches for parsing CSV files - using callbacks, a stream + callback as well as the Sync and Async API. We'll be covering the stream + callback API and the Sync API.
var fs = require('fs');
var parse = require('csv-parse');
var parser = parse({columns: true}, function (err, records) {
console.log(records);
});
fs.createReadStream(__dirname+'/chart-of-accounts.csv').pipe(parser);
, we create a parser
which accepts an object literal, containing the options we'd like to set. The second argument is the callback function that's used to access the records - or just print them out, in our case.
Options to specify for the fs include:
The delimiter option defaults to a comma
,
. If the data from the file you’re trying to parse uses some other delimiter like a semi-colon;
, or a pipe|
, you can specify that with this option.The cast option defaults to
false
and is used to indicate whether you want to cast the strings to their native data types. For example, a column that is made up of date fields can be cast into aDate
.The columns option is to indicate whether you want to generate the record in the form of object literals. By default, this column is set to
false
and records are generated by the parser in the form of arrays. If set totrue
, the parser will infer the column name from the first line.
...
Write file using csv-stringify
from the node-csv
suite. Stringification just means that we'll convert some data (JSON in our example) into a string. This string is then written to a file, in CSV format.
The csv-stringify
package also has a couple of API options, though, the Callback API offers a really simple way to stringify data, without the need to handle events like with the Stream API.
reading csv file with Stringifier
stringifier.on('readable', function(){
let row;
while(row = stringifier.read()){
data.push(row)
}
})
URL module
https://www.w3schools.com/nodejs/nodejs_url.asp
...
Mongoose and schema access to MongoDb
Populate on query result
’ll check the endpoint.
This should be setting sellingPrice
as a priceSchema
which is:
{
dollars: Number,
cents: Number (optional),
currency: 'usd' (default)
}
...
has been blocked by CORS policy
Access to XMLHttpRequest at 'https://ebc-api-dev.sysopsnetwork.com/authentication' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
What domain are you making your XMLHttpRequest
from and to? CORS is a client-side operation; first you need to identify (1) what page is making the blocked XMLHttpRequest
and then where it is making the request to. The error you pasted seem incomplete, so I'm not clear on how to help. Also it would help if you also included which domain the above Express code is running under as well.
https://github.com/expressjs/cors/issues/184
...
@dougwilson
Member
dougwilson commented on Jan 28, 2020
Gotcha. So which one of those parts are using XMLHttpRequest? It sounds to me based on your description like the XMLHttpRequest is the request to localhost:8090, which is redirected to sso.dol.gov. If this is the case, the sso.dol.gov domain is what needs CORS policy applied to it to allow calls from localhost:3200.
If this is the case, the sso.dol.gov domain is what needs CORS policy applied to it to allow calls from localhost:3200.
Handling CORS error in Nodejs
https://stackabuse.com/handling-cors-with-node-js/
Candidate Solutions
Magic Nodejs REST Angular CRUD generator - 600 per server
see demo - looks good
server pricing may be an issue except for smaller accounts on cloud or on-prem
Magic will read metadata from your database. It will use this metadata to generate an HTTP REST Web API for you, wrapping all CRUD operations inside of REST endpoints. Then it will use metadata from the REST API to automatically generate Angular components, router links, menu items, datagrids, etc. The end result becomes that before you’ve even had to create as much as a single line of code yourself, 90% of your job is already done.
...