Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some sublime options #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
responses
responses
files
29 changes: 26 additions & 3 deletions script.js → index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ const express = require('express'),
shell = require('shelljs'),

// Modify the folder path in which responses need to be stored
folderPath = './Responses/',
folderPath = './files/',
defaultFileExtension = 'json', // Change the default file extension
bodyParser = require('body-parser'),
DEFAULT_MODE = 'writeFile',
defaultEncoding ='utf-8',
path = require('path');

// Create the folder path in case it doesn't exist
Expand All @@ -21,7 +21,7 @@ app.get('/', (req, res) => res.send('Hello, I write data to file. Send them requ

app.post('/write', (req, res) => {
let extension = req.body.fileExtension || defaultFileExtension,
fsMode = req.body.mode || DEFAULT_MODE,
fsMode = req.body.mode ,
uniqueIdentifier = req.body.uniqueIdentifier ? typeof req.body.uniqueIdentifier === 'boolean' ? Date.now() : req.body.uniqueIdentifier : false,
filename = `${req.body.requestName}${uniqueIdentifier || ''}`,
filePath = `${path.join(folderPath, filename)}.${extension}`,
Expand All @@ -37,7 +37,30 @@ app.post('/write', (req, res) => {
}
});
});
app.get('/read', (req, res) => {
let extension = req.body.fileExtension || defaultFileExtension,
fsMode = req.body.mode ,
encoding= req.body.encoding || defaultEncoding
uniqueIdentifier = req.body.uniqueIdentifier ? typeof req.body.uniqueIdentifier === 'boolean' ? Date.now() : req.body.uniqueIdentifier : false,
filename = `${req.body.requestName}${uniqueIdentifier || ''}`,
filePath = `${path.join(folderPath, filename)}.${extension}`,
options = req.body.options || undefined;
console.log(filePath);

fs[fsMode](filePath, encoding, (err,data) => {
if (data){
console.log("OK data retrieved");
res.send(data);
} else if (err) {
console.log("errror:"+err);
res.send('Error');
} else
{
console.log(req);
res.send('No data');
}
});
});
app.listen(3000, () => {
console.log('ResponsesToFile App is listening now! Send them requests my way!');
console.log(`Data is being stored at location: ${path.join(process.cwd(), folderPath)}`);
Expand Down
Loading