Before publishing to NPM, chmod.
chmod 775 ./
This will keep users from getting the following error when downloading the package.
npm ERR! Error: ENOENT, chmod '/usr/local/lib/node_modules/
Before publishing to NPM, chmod.
chmod 775 ./
This will keep users from getting the following error when downloading the package.
npm ERR! Error: ENOENT, chmod '/usr/local/lib/node_modules/
Here’s what I did to enable gzip compression.
npm install compression
In the ./config/http.js, add the following code.
middleware: {
compress: require('compression')(),
}
Note this will universally enable gzip compression.
Published a node command module to automate the creation of Models and Controllers for a SailsJS api.
This is a node.js command line utility that creates SailsJS base Models and Controllers for API use.
This utility is available on npm. Globally install it by using the -g flag:
bash
npm install -g csmsc
To use it, cd
into a project directory, and run csmsc
with -n and -f args to represent model name and properties respectively.
Make a model and controller for ‘modelName’ with properties ‘primaryproperty’, ‘anotherproperty’ and ‘aThirdproperty’:
bash
csmsc -n ModelName -f firstprop,secondprop,thirdprop
bash
csmsc -n ModelName -f title,url,subtitle,text,author -c tags -m company
SailsJS expects controllers and models to be created using Pascal Case please appropriately name Models with the first character uppercase to ensure compatibility.
csmsc will write the model into the api/models/ folder. csmsc will write the controller into the api/controllers/ folder.
Existing files will be over written.
Model properties are string by default, modify as needed.
MongoDb will add the following
_id as a unique identifier.
createdAt date created.
updatedAt date last updated.
csmsc will add the following
createdBy user that created the record.
updatedBy user that last updated the record.
createdBy and updatedBy values must be passed to the api or will default to ‘admin’
-n is the name of the model and controller.
-f is a list of comma separated fields
-c is a list of comma separated collections (one to many)
-m is a list of comma separated models (one to one)
the first field in the field list is considered the primary field.
csmsc -n NewModel -f one,two,three
http://localhost:1337/newmodel/model/
http://localhost:1337/newmodel/displayOrder/
http://localhost:1337/newmodel/get/
mongodb’s auto generated id will be used as the key primaryFild will be the value for that key
http://localhost:1337/newmodel/search/la?field=ObjectName
Search string follows the slash
Field string is optional and follows ?field=
Using a search string without a field name will search the primary field / node of the object.
Using a search string with a field name specified will search the specified field / node for the string provided.
Limit
&limit=
Skip
&skip=
Implementation is not complete, this is a placeholder.
https://www.npmjs.com/package/csmsc
I created and published a command line tool to generate my Models and Controllers for a SailsJS API.
The process is the same as writing anything for node but requires the following at the top of the main script.
#!/usr/bin/env node
And the following addition in the package.json file.
"preferGlobal": true,
"bin": {
"commandlineCommand": "./bin/mainScript.js"
}
Commit the project to github or another repository and publish to npmjs.org using the following commands.
npm set init.author.name "Your Name"
npm set init.author.email "email@email.com"
npm set init.author.url "http://www.projectWebsite.com/"
npm adduser
npm publish ./
Finished.