Unable to include .key file in typescript build





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







2















I have a public.key and private.key file in my folder structure that is not being included in the build ie, when I run tsc.



I am using the public/private key pairs to generate a json web token.
This is how i am importing the file which works fine and generates the token.



private publicKey = fs.readFileSync(path.join(__dirname, "../../utils/keys/public.key"), "utf8");


Same code applies for the private.key just with the filename change.



This is my tsconfig.json file



{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es6",
"noImplicitAny": false,
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist/",
"pretty": true,
"baseUrl": ".",
"alwaysStrict": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"paths": {
"*": ["node_modules/*", "src/*", "*"]
}
},
"include": ["src/**/**/*.ts"],
"exclude": ["node_modules"]
}


Is there a way I ask typescript to include the *.key file?










share|improve this question

























  • The question lacks stackoverflow.com/help/mcve . How do you use the file and why is it expected to be included?

    – estus
    Nov 16 '18 at 14:57











  • @estus updated the question to reflect the same

    – Jude Fernandes
    Nov 16 '18 at 15:45











  • This may be not a duplicate of stackoverflow.com/questions/36690779/typescript-copy-files because of XY problem.

    – estus
    Nov 16 '18 at 15:52


















2















I have a public.key and private.key file in my folder structure that is not being included in the build ie, when I run tsc.



I am using the public/private key pairs to generate a json web token.
This is how i am importing the file which works fine and generates the token.



private publicKey = fs.readFileSync(path.join(__dirname, "../../utils/keys/public.key"), "utf8");


Same code applies for the private.key just with the filename change.



This is my tsconfig.json file



{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es6",
"noImplicitAny": false,
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist/",
"pretty": true,
"baseUrl": ".",
"alwaysStrict": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"paths": {
"*": ["node_modules/*", "src/*", "*"]
}
},
"include": ["src/**/**/*.ts"],
"exclude": ["node_modules"]
}


Is there a way I ask typescript to include the *.key file?










share|improve this question

























  • The question lacks stackoverflow.com/help/mcve . How do you use the file and why is it expected to be included?

    – estus
    Nov 16 '18 at 14:57











  • @estus updated the question to reflect the same

    – Jude Fernandes
    Nov 16 '18 at 15:45











  • This may be not a duplicate of stackoverflow.com/questions/36690779/typescript-copy-files because of XY problem.

    – estus
    Nov 16 '18 at 15:52














2












2








2


0






I have a public.key and private.key file in my folder structure that is not being included in the build ie, when I run tsc.



I am using the public/private key pairs to generate a json web token.
This is how i am importing the file which works fine and generates the token.



private publicKey = fs.readFileSync(path.join(__dirname, "../../utils/keys/public.key"), "utf8");


Same code applies for the private.key just with the filename change.



This is my tsconfig.json file



{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es6",
"noImplicitAny": false,
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist/",
"pretty": true,
"baseUrl": ".",
"alwaysStrict": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"paths": {
"*": ["node_modules/*", "src/*", "*"]
}
},
"include": ["src/**/**/*.ts"],
"exclude": ["node_modules"]
}


Is there a way I ask typescript to include the *.key file?










share|improve this question
















I have a public.key and private.key file in my folder structure that is not being included in the build ie, when I run tsc.



I am using the public/private key pairs to generate a json web token.
This is how i am importing the file which works fine and generates the token.



private publicKey = fs.readFileSync(path.join(__dirname, "../../utils/keys/public.key"), "utf8");


Same code applies for the private.key just with the filename change.



This is my tsconfig.json file



{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es6",
"noImplicitAny": false,
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist/",
"pretty": true,
"baseUrl": ".",
"alwaysStrict": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"paths": {
"*": ["node_modules/*", "src/*", "*"]
}
},
"include": ["src/**/**/*.ts"],
"exclude": ["node_modules"]
}


Is there a way I ask typescript to include the *.key file?







node.js typescript express typescript-typings tsconfig






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 15:44







Jude Fernandes

















asked Nov 16 '18 at 14:17









Jude FernandesJude Fernandes

3,12652457




3,12652457













  • The question lacks stackoverflow.com/help/mcve . How do you use the file and why is it expected to be included?

    – estus
    Nov 16 '18 at 14:57











  • @estus updated the question to reflect the same

    – Jude Fernandes
    Nov 16 '18 at 15:45











  • This may be not a duplicate of stackoverflow.com/questions/36690779/typescript-copy-files because of XY problem.

    – estus
    Nov 16 '18 at 15:52



















  • The question lacks stackoverflow.com/help/mcve . How do you use the file and why is it expected to be included?

    – estus
    Nov 16 '18 at 14:57











  • @estus updated the question to reflect the same

    – Jude Fernandes
    Nov 16 '18 at 15:45











  • This may be not a duplicate of stackoverflow.com/questions/36690779/typescript-copy-files because of XY problem.

    – estus
    Nov 16 '18 at 15:52

















The question lacks stackoverflow.com/help/mcve . How do you use the file and why is it expected to be included?

– estus
Nov 16 '18 at 14:57





The question lacks stackoverflow.com/help/mcve . How do you use the file and why is it expected to be included?

– estus
Nov 16 '18 at 14:57













@estus updated the question to reflect the same

– Jude Fernandes
Nov 16 '18 at 15:45





@estus updated the question to reflect the same

– Jude Fernandes
Nov 16 '18 at 15:45













This may be not a duplicate of stackoverflow.com/questions/36690779/typescript-copy-files because of XY problem.

– estus
Nov 16 '18 at 15:52





This may be not a duplicate of stackoverflow.com/questions/36690779/typescript-copy-files because of XY problem.

– estus
Nov 16 '18 at 15:52












1 Answer
1






active

oldest

votes


















1














TypeScript transpiles *.ts* and *.js* files. This isn't a task for TypeScript to process non-script files and include them into a build.



Bundling is a task for Webpack, which can be used to load arbitrary files with respective loaders, e.g. file-loader, but files are expected to be used with import or require in this case and not fs. Also isn't necessary to use Webpack with Node.js applications because they don't benefit from this that much as client-side applications.



In this case keys shouldn't be a part of dist at all, unless proven otherwise. It can reside outside of src or dist and be on the same level of nesting:



dist
...
src
...
util
keys


Since relative paths are expected to be same within both src and dist, there should be no problems linking to util/keys






share|improve this answer
























  • that sounds great but the problem arises when I'm trying to deploy on heroku, I need to run a git push to heroku which will do an npm installl and then run tsc to transpile the files to js and runs the server, Now in order for the server to generate token It would need the keys, how do I handle something like that on heroku? Environment variables?

    – Jude Fernandes
    Nov 16 '18 at 18:07








  • 1





    I'm not sure what the problem is. Just commit key files to the repo. You have other files besides src/dist that are needed for the app to run, like package.json. Key files are among these files.

    – estus
    Nov 16 '18 at 18:15











  • Yep just tried it, works perfectly, thank you so much. Is there a better way of deploying private keys to heroku ie, should they be converted to a string and used as an env variable?

    – Jude Fernandes
    Nov 16 '18 at 18:33








  • 1





    Giad it worked. This depends on how private these private keys are. I don't use Heroku myself but yes, environment variable is a good place to store things you don't want to commit, especially if a key is a string. In this case you may want to read a key from process.env first before trying fs.readFileSync

    – estus
    Nov 16 '18 at 19:01














Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53339613%2funable-to-include-key-file-in-typescript-build%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














TypeScript transpiles *.ts* and *.js* files. This isn't a task for TypeScript to process non-script files and include them into a build.



Bundling is a task for Webpack, which can be used to load arbitrary files with respective loaders, e.g. file-loader, but files are expected to be used with import or require in this case and not fs. Also isn't necessary to use Webpack with Node.js applications because they don't benefit from this that much as client-side applications.



In this case keys shouldn't be a part of dist at all, unless proven otherwise. It can reside outside of src or dist and be on the same level of nesting:



dist
...
src
...
util
keys


Since relative paths are expected to be same within both src and dist, there should be no problems linking to util/keys






share|improve this answer
























  • that sounds great but the problem arises when I'm trying to deploy on heroku, I need to run a git push to heroku which will do an npm installl and then run tsc to transpile the files to js and runs the server, Now in order for the server to generate token It would need the keys, how do I handle something like that on heroku? Environment variables?

    – Jude Fernandes
    Nov 16 '18 at 18:07








  • 1





    I'm not sure what the problem is. Just commit key files to the repo. You have other files besides src/dist that are needed for the app to run, like package.json. Key files are among these files.

    – estus
    Nov 16 '18 at 18:15











  • Yep just tried it, works perfectly, thank you so much. Is there a better way of deploying private keys to heroku ie, should they be converted to a string and used as an env variable?

    – Jude Fernandes
    Nov 16 '18 at 18:33








  • 1





    Giad it worked. This depends on how private these private keys are. I don't use Heroku myself but yes, environment variable is a good place to store things you don't want to commit, especially if a key is a string. In this case you may want to read a key from process.env first before trying fs.readFileSync

    – estus
    Nov 16 '18 at 19:01


















1














TypeScript transpiles *.ts* and *.js* files. This isn't a task for TypeScript to process non-script files and include them into a build.



Bundling is a task for Webpack, which can be used to load arbitrary files with respective loaders, e.g. file-loader, but files are expected to be used with import or require in this case and not fs. Also isn't necessary to use Webpack with Node.js applications because they don't benefit from this that much as client-side applications.



In this case keys shouldn't be a part of dist at all, unless proven otherwise. It can reside outside of src or dist and be on the same level of nesting:



dist
...
src
...
util
keys


Since relative paths are expected to be same within both src and dist, there should be no problems linking to util/keys






share|improve this answer
























  • that sounds great but the problem arises when I'm trying to deploy on heroku, I need to run a git push to heroku which will do an npm installl and then run tsc to transpile the files to js and runs the server, Now in order for the server to generate token It would need the keys, how do I handle something like that on heroku? Environment variables?

    – Jude Fernandes
    Nov 16 '18 at 18:07








  • 1





    I'm not sure what the problem is. Just commit key files to the repo. You have other files besides src/dist that are needed for the app to run, like package.json. Key files are among these files.

    – estus
    Nov 16 '18 at 18:15











  • Yep just tried it, works perfectly, thank you so much. Is there a better way of deploying private keys to heroku ie, should they be converted to a string and used as an env variable?

    – Jude Fernandes
    Nov 16 '18 at 18:33








  • 1





    Giad it worked. This depends on how private these private keys are. I don't use Heroku myself but yes, environment variable is a good place to store things you don't want to commit, especially if a key is a string. In this case you may want to read a key from process.env first before trying fs.readFileSync

    – estus
    Nov 16 '18 at 19:01
















1












1








1







TypeScript transpiles *.ts* and *.js* files. This isn't a task for TypeScript to process non-script files and include them into a build.



Bundling is a task for Webpack, which can be used to load arbitrary files with respective loaders, e.g. file-loader, but files are expected to be used with import or require in this case and not fs. Also isn't necessary to use Webpack with Node.js applications because they don't benefit from this that much as client-side applications.



In this case keys shouldn't be a part of dist at all, unless proven otherwise. It can reside outside of src or dist and be on the same level of nesting:



dist
...
src
...
util
keys


Since relative paths are expected to be same within both src and dist, there should be no problems linking to util/keys






share|improve this answer













TypeScript transpiles *.ts* and *.js* files. This isn't a task for TypeScript to process non-script files and include them into a build.



Bundling is a task for Webpack, which can be used to load arbitrary files with respective loaders, e.g. file-loader, but files are expected to be used with import or require in this case and not fs. Also isn't necessary to use Webpack with Node.js applications because they don't benefit from this that much as client-side applications.



In this case keys shouldn't be a part of dist at all, unless proven otherwise. It can reside outside of src or dist and be on the same level of nesting:



dist
...
src
...
util
keys


Since relative paths are expected to be same within both src and dist, there should be no problems linking to util/keys







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 16 '18 at 15:58









estusestus

79.2k23116236




79.2k23116236













  • that sounds great but the problem arises when I'm trying to deploy on heroku, I need to run a git push to heroku which will do an npm installl and then run tsc to transpile the files to js and runs the server, Now in order for the server to generate token It would need the keys, how do I handle something like that on heroku? Environment variables?

    – Jude Fernandes
    Nov 16 '18 at 18:07








  • 1





    I'm not sure what the problem is. Just commit key files to the repo. You have other files besides src/dist that are needed for the app to run, like package.json. Key files are among these files.

    – estus
    Nov 16 '18 at 18:15











  • Yep just tried it, works perfectly, thank you so much. Is there a better way of deploying private keys to heroku ie, should they be converted to a string and used as an env variable?

    – Jude Fernandes
    Nov 16 '18 at 18:33








  • 1





    Giad it worked. This depends on how private these private keys are. I don't use Heroku myself but yes, environment variable is a good place to store things you don't want to commit, especially if a key is a string. In this case you may want to read a key from process.env first before trying fs.readFileSync

    – estus
    Nov 16 '18 at 19:01





















  • that sounds great but the problem arises when I'm trying to deploy on heroku, I need to run a git push to heroku which will do an npm installl and then run tsc to transpile the files to js and runs the server, Now in order for the server to generate token It would need the keys, how do I handle something like that on heroku? Environment variables?

    – Jude Fernandes
    Nov 16 '18 at 18:07








  • 1





    I'm not sure what the problem is. Just commit key files to the repo. You have other files besides src/dist that are needed for the app to run, like package.json. Key files are among these files.

    – estus
    Nov 16 '18 at 18:15











  • Yep just tried it, works perfectly, thank you so much. Is there a better way of deploying private keys to heroku ie, should they be converted to a string and used as an env variable?

    – Jude Fernandes
    Nov 16 '18 at 18:33








  • 1





    Giad it worked. This depends on how private these private keys are. I don't use Heroku myself but yes, environment variable is a good place to store things you don't want to commit, especially if a key is a string. In this case you may want to read a key from process.env first before trying fs.readFileSync

    – estus
    Nov 16 '18 at 19:01



















that sounds great but the problem arises when I'm trying to deploy on heroku, I need to run a git push to heroku which will do an npm installl and then run tsc to transpile the files to js and runs the server, Now in order for the server to generate token It would need the keys, how do I handle something like that on heroku? Environment variables?

– Jude Fernandes
Nov 16 '18 at 18:07







that sounds great but the problem arises when I'm trying to deploy on heroku, I need to run a git push to heroku which will do an npm installl and then run tsc to transpile the files to js and runs the server, Now in order for the server to generate token It would need the keys, how do I handle something like that on heroku? Environment variables?

– Jude Fernandes
Nov 16 '18 at 18:07






1




1





I'm not sure what the problem is. Just commit key files to the repo. You have other files besides src/dist that are needed for the app to run, like package.json. Key files are among these files.

– estus
Nov 16 '18 at 18:15





I'm not sure what the problem is. Just commit key files to the repo. You have other files besides src/dist that are needed for the app to run, like package.json. Key files are among these files.

– estus
Nov 16 '18 at 18:15













Yep just tried it, works perfectly, thank you so much. Is there a better way of deploying private keys to heroku ie, should they be converted to a string and used as an env variable?

– Jude Fernandes
Nov 16 '18 at 18:33







Yep just tried it, works perfectly, thank you so much. Is there a better way of deploying private keys to heroku ie, should they be converted to a string and used as an env variable?

– Jude Fernandes
Nov 16 '18 at 18:33






1




1





Giad it worked. This depends on how private these private keys are. I don't use Heroku myself but yes, environment variable is a good place to store things you don't want to commit, especially if a key is a string. In this case you may want to read a key from process.env first before trying fs.readFileSync

– estus
Nov 16 '18 at 19:01







Giad it worked. This depends on how private these private keys are. I don't use Heroku myself but yes, environment variable is a good place to store things you don't want to commit, especially if a key is a string. In this case you may want to read a key from process.env first before trying fs.readFileSync

– estus
Nov 16 '18 at 19:01






















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53339613%2funable-to-include-key-file-in-typescript-build%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues